Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the difference between selectors?

Status
Not open for further replies.

Albion

IS-IT--Management
Aug 8, 2000
517
US
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.

thanks

-Al
 
Hi

[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.


Feherke.
 
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

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top