1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Combining ID and class selector in CSS seems to fail

Discussion in 'CSS' started by blakenzoe, Jul 24, 2008.

  1. #1
    My different color styles don't get applied when I combine class and ID selectors. My font color remains #999. Using the Firebug plugin for Firefox 3, I don't even see the multiple-selector CSS being picked up. Anybody know why?

    Here is the CSS, taken from main.css:

    #headercontent {color: #999;}
    .home #headercontent { color: #f00; }
    .sublevel #headercontent { color: #0f0; }

    ... and the following HTML snippets, each from two different pages:
    HOMEPAGE:
    <div id="headercontent" class="home">This is a test</div>
    2ND LEVEL PAGE:
    <div id="headercontent" class="sublevel">This is a test</div>

    TIA,
    blakenzoe
     
    blakenzoe, Jul 24, 2008 IP
  2. glorie

    glorie Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That won't work.

    this code (.sublevel #headercontent { color: #0f0; }) could would only work if your xhtml code is like this:


    
    <div class="sublevel">
     <div id="headercontent"></div>
    </div>
    
    Code (markup):
    your code should be like this:
    
    .home {color: #f00 !important;}
    .sublevel { color: #0f0 !important; }
     
    Code (markup):
     
    glorie, Jul 24, 2008 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    or just remove the spaces. If you are trying to combine the same class on the same ID, you can't have the space between them. The space, as glorie implies, indicates it's a child div, not the same one.

    I would code that CSS with the ID first.
    
    #headercontent {color: #999;}
    #headercontent.home { color: #F00; }
    #headercontent.sublevel { color: #0F0; }
    
    Code (markup):
    That should do what you want.
     
    deathshadow, Jul 24, 2008 IP
  4. blakenzoe

    blakenzoe Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you both. The implied parent-child relationship is what I had failed to understand. All makes sense now!

    -blakenzoe
     
    blakenzoe, Jul 24, 2008 IP