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
.
element1~element2 { style properties }
element1~element2 |
Yes | 7.0 | Yes | Yes | Yes |
An example showing how to use element1~element2
CSS selector.
<!DOCTYPE html>
<html>
<head>
<style>
p~h2{<!-- ww w . java 2 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>