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.

Multi class element help

Discussion in 'CSS' started by eamiro, Sep 10, 2009.

  1. #1
    Hi,

    In this case:

    <div class="class1 class2">
    
     <p>My paragraph></p>
    
    </div>
    HTML:
    How can I style the paragraph element?

    Will this work?

    .class1 p{ style } ?
     
    eamiro, Sep 10, 2009 IP
  2. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Did you try it and see? : )

    But if your question was, to only give this style to paragaphs who are in boxes with BOTH classes on it (meaning you don't want the style if the box around it only has one or the other classes) you can do this:

    .class1.class2 p {styles for p's whose parents/ancestors have BOTH classes;}

    See, no space as descendant selector between the two classes.
     
    Stomme poes, Sep 10, 2009 IP
    eamiro likes this.
  3. eamiro

    eamiro Well-Known Member

    Messages:
    274
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #3
    This is right what I wanted, thanks a lot Stomme poes
     
    eamiro, Sep 10, 2009 IP
  4. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What you posted above
    .class1 p {styles} will work for any box with that style on it.

    .class2 p {styles} will work for any box with that style.

    So you don't need to list BOTH styles to get the p styled UNLESS you only want p's whose parents have BOTH to get styled. I want to make sure I didn't confuse you.

    <div class="class1 class2"><p>stuff</p></div>

    this p can be styled with any of the code above

    but you can also have this in your HTML
    <div class="class1"> and a <p> inside it</div>

    If you didn't want this p to get the same styles as the p above whose parent has both classes, then you'd need the .class1.class2 p {styles} for the first p and something else (like .class1 p {styles}) for the other p

    but if it's ok for the p in teh first HTML AND the p in the second HTML examples to both have the same styles, then
    .class1 p {styles}
    is fine and what you want.
     
    Stomme poes, Sep 10, 2009 IP