element1~element2

In this chapter you will learn:

  1. Definition for Selector element1~element2
  2. An example showing how to use element1~element2 CSS selector

Description

The element1~element2 selector selects element2 that are preceded by element1.

Both elements must have the same parent. element2 does not have to be immediately preceded by element1.

Example

<!DOCTYPE html><!-- ja  va 2 s  .c om-->
<html>
<head>
<style> 
p~h2{
   background:red;
}
</style>
</head>
<body>
    <div>A div element.</div>
    <p>The first paragraph.</p>
    <h2>Another list</h2>
    <p>The second paragraph.</p>
</body>
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. Definition for Selector :lang
  2. An example showing how to use :lang CSS selector
Home » HTML CSS Tutorial » CSS Selector Reference
.class
#id
*
element
element,element
element element
element>element
element+element
element1~element2
:lang
:link
:visited
:active
:hover
:focus
:first-letter
:first-line
:first-child
:last-child
:only-child
:nth-child(n)
:nth-last-child(n)
:before
:after
:first-of-type
:last-of-type
:only-of-type
:nth-of-type(n)
:nth-last-of-type(n)
:root
:empty
:target
:enabled
:disabled
:checked
:not
::selection
[attribute]
[attribute=value]
[attribute~=value]
[attribute|=value]
[attribute^=value]
[attribute$=value]
[attribute*=value]