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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Descendant Selectors - Shed some light 1

Status
Not open for further replies.

jacksbackw

Technical User
Mar 24, 2005
6
US
I have been studying CSS for quite some time now and have a question that perhaps someone can easily answer.

Take the following style for example:

TD#leftside TD {border-bottom: 1px solid #a98763;}

Why have the TD in front of the ID if you are using a descendant selector to target the TD already? Is it's purpose to somehow identify what type of element the ID is associated with?

It seems to work without the preceding TD, so why?

Thanks in advance,
Jackbackw
 

Jeff is spot on. Apart from helping identify the possible location for the element with that ID (i.e. clarity reasons), the big difference is specicifity.

Basically, your selector will have a weighting attached to it, which is calculated (see the link Jeff gave) from many factors, including the use of classes and IDs.

For example, you might have a style sheet that you are inheriting that has a very specific selector. To override the behviour given by that selector, you might have to use an equally specific selector, rather than a more generic one.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
That answers my question perfectly!

Thank you all for the clarification!

Laith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top