How to select the above element of an element in CSS using selectors
<li class="content">One</li> <li class="content">Two</li> <li class="content">Three</li> <li class="no-content">First</li> <li class="content">Four</li> <li class="content">Five</li> <li class="content">Six</li>
Here I want to use the class no-content
, so that I can get its above element <li class="content">Three</li>
, using CSS selector.
No, there is no "previous sibling" selector. On a related note, ~ is for general successor sibling (meaning the element comes after this one, but not necessarily immediately after) and is a CSS3 selector. + is for next sibling and is CSS2.
The general sibling selector (~) selects all elements that are next siblings of a specified element.
This is not possible with pure CSS...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With