Can't stop a div class from inheriting styles from parent div!

Discussion in 'CSS' started by markowe, Oct 6, 2010.

  1. #1
    OK, this is driving me insane!

    In one external css file I have this:

    #content h3 {
        color: #444444;
        font-size: 18px;
        font-family: Georgia, "Times New Roman", Times, serif;
        font-weight: normal;
        margin: 25px 0px 0px 0px;
        padding: 10px 0px 10px 0px;
        }
    Code (markup):
    and in another external css (it belongs to a plugin, that's why it's separate) I have:

    div.mysubdiv h3 {
    margin: 0;
    padding: 0;
    }
    Code (markup):
    Now, the div with class 'mysubdiv' is found WITHIN the div with ID 'content' yet no matter what I do, 'mysubdiv' continues to inherit the margins (the 25px top margin is bugging me) from the parent div - and some other attributes too, I have just simplified the problem. Yet some attributes I CAN override. What's with that, anything obvious anyone can see here?!
     
    markowe, Oct 6, 2010 IP
  2. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Did you try this?
    
    #content .mysubdiv h3 {
    properties...
    ...
    ...
    }
    
    Code (markup):
     
    radiant_luv, Oct 6, 2010 IP
    markowe likes this.
  3. anupviews

    anupviews Member

    Messages:
    795
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #3
    I know why you are going insane.
    #content h3 {
    color: #444444;
    font-size: 18px;
    font-family: Georgia, "Times New Roman", Times, serif;
    font-weight: normal;
    margin: 25px 0px 0px 0px;
    padding: 10px 0px 10px 0px;
    }
    doesn't carries information for class="content" rather it carries the CSS information for <div class="content"><h3>This</h3></div>

    Change your CSS properties in

    #content {
    ...
    }


    Not in #content h3 {
    ...
    }

    Hope this helps
     
    anupviews, Oct 7, 2010 IP
  4. markowe

    markowe Well-Known Member

    Messages:
    1,136
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    165
    #4
    Thanks for the help everyone, the above solution actually put me on the right track. I don't know why I thought the parent div didn't need to be specified in the class definition, but there you go. Actually, I have a parent div within my actual plugin, so I specified THAT div rather than #content - because it's for a plugin I can't know for sure that the user will have a parent div called #content, otherwise the other solution would have been fine too.

    Thanks again. Sigh, so much to learn about css still...
     
    markowe, Oct 7, 2010 IP