Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector for one tag directly followed by another tag

This selects all <B> tags directly preceded by <A> tags:

A+B {     /* styling */ } 

What is the selector for all <A> tags directly followed by <B> tags?

Here's sample HTML fitting my question:

<a>some text</a> <b>some text</b> 
like image 951
Mostafa Farghaly Avatar asked Jul 15 '09 16:07

Mostafa Farghaly


People also ask

Can we use ID selector in multiple tags?

The ID Selector must UNIQUE. If you want to set the same ID for multiple elements, You should better use the class .

How can we combine two selectors in HTML?

The descendant combinator — typically represented by a single space (" ") character — combines two selectors such that elements matched by the second selector are selected if they have an ancestor (parent, parent's parent, parent's parent's parent, etc) element matching the first selector.


1 Answers

Do you mean to style A given that it has a B element directly inside or followed? Like this:

<A>     <B>     </B> </A>  // OR  <A> </A> <B> </B> 

You can't do such a thing in CSS (yet). Eric Meyer states that this kind of selector has been discussed quite a few times on the CSS mailing list, and isn’t doable. Dave Hyatt, one of the core WebKit developers, comments with a good explanation of why it can’t be done.

Check out: Shaun Inman's blog post and the comment by Eric Meyer.
David Hyatt weighs in, too.

like image 176
Nick Presta Avatar answered Oct 01 '22 01:10

Nick Presta