pstein Posted October 25, 2017 Share Posted October 25, 2017 Assume I have the following code <p> <div>.aaa...</div> <div class="foobar">.bbb..</div> <div>.ccc..</div> <p> 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 Peter Link to comment Share on other sites More sharing options...
dsonesuk Posted October 25, 2017 Share Posted October 25, 2017 You can use nth-child() https://www.w3schools.com/cssref/sel_nth-child.asp or first-of-type() https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_first-of-type Link to comment Share on other sites More sharing options...
Ingolme Posted October 25, 2017 Share Posted October 25, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now