Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
#id_name selector precedence
Old 10-04-2007, 08:12 PM #id_name selector precedence
Extreme Talker

Posts: 238
Location: United States
Trades: 0
I've noticed that whenever I have a selector that starts with #id_name, it has the highest precedence, even if I put something lower in the CSS file that should override it. This occurs in all 3 browsers I use (IE, FF, Opera), so I'm thinking it's intentional in the standard somewhere.

Here is an example:
Code:
#main .corner{
    height: 10px;
}
.display .corner{
    height: 7px;
}

----

<div id="main">
    <!-- other markup here -->
    <div class="display">
       <div class="corner"></div>
        <!-- other markup here -->
    </div>
</div>
The <div class="corner"> will have a height of 10px instead of 7px. I know I can use !important, but I'm just curious why this occurs in my example. Does anyone have any ideas?
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.

Last edited by frost; 10-04-2007 at 08:13 PM.. Reason: OOPS, typo
frost is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-04-2007, 09:48 PM Re: #id_name selector precedence
LadynRed's Avatar
Defies a Status

Posts: 10,016
Location: Tennessee
Trades: 0
You're bumping into specificity as well as the cascade.

#main .corner is very specific and will over ride .display .corner every time.

http://www.htmldog.com/guides/cssadvanced/specificity/
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 10-05-2007, 12:20 AM Re: #id_name selector precedence
Extreme Talker

Posts: 238
Location: United States
Trades: 0
I didn't know about the different levels of specificity, but I guess it makes sense. Thanks.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 10-05-2007, 07:31 AM Re: #id_name selector precedence
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Good article on specificity using the Sith power analogy http://www.stuffandnonsense.co.uk/ar...city_wars.html.

Basically an Id trumps a class which trumps an element. Problem lies when they are combined.
maxxximus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to #id_name selector precedence
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26350 seconds with 12 queries