What is the difference between "div#selector {}", "#selector {}", and "div #selector {}"? I see how "#selector" can be used no matter what the parent is, but I don't get the difference between the other two.
[tt]div#selector {} [/tt] - [tt]div[/tt] element with [tt]id[/tt] equal to "selector"
[tt]#selector {} [/tt] - any tag with [tt]id[/tt] equal to "selector"
[tt]div #selector {}[/tt] - any element with [tt]id[/tt] equal to "selector" descendant of a [tt]div[/tt] element
See Selectors in CSS 2.1 and test your styles on the SelectORacle site suggested by Vragabond.
Also, look into the term "specificity" with regards to CSS rules.
It's basically a weighting given to rules to determine which rule will take precedence.
In the case of the two rules you posted that potentially target the same element ("div#selector" and "#selector"), the former has a higher specificity, and thus would take precedence.
Hope this helps,
Dan
Coedit Limited - Delivering standards compliant, accessible web solutions
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.