Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CSS3 - select element after another element

CSS3 - select element after another element

Problem

Is it possible with CSS3 to select an element that comes right after another? If I have, for example:

One Two Three Four

I want to select the class="b" anchor that comes after the class="a" anchor only. So I'd want the "Two" anchor selected and not the "Four" anchor.

Is that possible in CSS3? If not, is it possible in jQuery? (though, I'd prefer CSS).

Problem courtesy of: Mr Mikkél

Solution

You don't need CSS 3 for this, it was already possible in CSS 2.1! :)

Use the adjacent sibling selector + :

.a + .b {
   /* styles */
}
Solution courtesy of: rink.attendant.6

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

CSS3 - select element after another element

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×