CSS Selector element1~element2

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>
<html>
<head>
<style> 
p~h2{<!--  w  ww .  ja  v  a2  s . c o  m-->
   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

The code above generates the following result.

element1~element2




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference