HTML CSS examples for CSS Selector:element not immediately sibling
The element1~element2 selector selects of element2 preceded by element1.
Both elements must have the same parent, but element2 does not have to be immediately preceded by element1.
Select all <div> elements that are preceded by a <p> element with the same parent.
<!DOCTYPE html> <html> <head> <style> p ~ ul { background: #ff0000; } </style><!-- ww w .j ava 2s.c o m--> </head> <body> <div>A div element.</div> <div>div</div> <p>The first paragraph.</p> <div>div</div> <h2>Another list</h2> <div>div</div> </body> </html>