Jump to content

Searching opposite of "+": Predecessor element

Recommended Posts

Assume I have the following code

<div class="foobar">.bbb..</div>

then I can address the <div>element FOLLOWING the <div> element with class=foobar by

div.foobar + div

will address the <div> with ccc inside

Ok, but how do I address the opposite: The predecessor=the <div> with aaa inside?

div.foobar - div

seems not to work


Share this post

Link to post
Share on other sites

CSS does not have predecessor or ancestor selectors because the CSS rendering engine is stateless, it only moves forward and down the DOM tree without having to backtrack. Being stateless means that it is efficient and can render pages really quickly.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now