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>
The code above generates the following result.