Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

CSS code cleanup question

Options
  • 13-05-2006 3:02pm
    #1
    Posts: 0


    Hey all,

    Just a quick question regarding inheritance in CSS files (i'm not exactly a master of CSS :) )
    I have a class of DIV, and I want other similar DIVs to have the same basic look.
    The DIV code is as follows:

    border: 1px dashed;
    margin: 20px auto 20px auto;
    padding: 20px;
    width: 55%;
    background-color: #FFFFFF;

    Instead of copying and pasting those attributes, how would I setup other DIVs to "inherit" these values?
    Or would child DIVs within the above one automatically inherit these attributes?

    Thanks for any help


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma




  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Divs within Divs don't inherit all of the parent values. However there are certain attributes that are inherited. Afaik, any font values you put in a BODY declaration are inherited by all elements unless they're overridden, for example.

    All you do is make the declaration, e.g.
    DIV.myClass {
       border: 1px dashed;
       margin: 20px auto 20px auto;
       padding: 20px;
       width: 55%;
       background-color: #FFFFFF;
    }
    
    Then any Divs that you want to have these attributes, you apply the "class" paramater, i.e. <div class = "myClass">......</div>


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    would

    div {
    border: 1px dashed;
    margin: 20px auto 20px auto;
    padding: 20px;
    width: 55%;
    background-color: #FFFFFF;
    }

    not do the trick for you ... all div's will therefore have this style ?


  • Posts: 0 [Deleted User]


    Thanks all for the help, i'll try and rearrange my code now, trying to avoid repetition.

    error9, would that not make all divs like that?
    I only want certain ones to act like this, there are a lot of divs in my page.

    Thanks


  • Registered Users Posts: 3,594 ✭✭✭forbairt


    sorry I miss read what you were up to :)


  • Advertisement
Advertisement