Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Doctor_Varney's Avatar
    Join Date
    Mar 2008
    Location
    Midlands, UK
    Posts
    649
    Thanks
    45
    Thanked 29 Times in 28 Posts

    Safe use of class to override margin default?

    The plan is to set up global attributes for things in my stylesheet, then override them, at will, with specified .classes.

    Can anyone take a quick look and tell me if this is going to be ok, in all browsers? That a .class will take precedence over a default setting? Hopefully, I'm on the right track here.

    My HTML says:
    Code:
    <body id="page-one">
    
    <p class="margin1"><img src="../folder/file.jpg" />
    paragraph text, using specified margin
    </p>
    
    <p class="margin2"><img src="../folder/file.jpg" />
    Paragraph text, using specified margin
    </p>
    
    <p><img src="../folder/file.jpg />
    Paragraph text, using my default margin
    </p>
    
    </body>
    And my CSS reads:
    Code:
    /*These are the defaults*/
    #page-one p { font-size:0.8em; float:left; margin:1em 0 0 0 }
    #page-one img { display:block; margin:0 0 1em 0 }
    
    /*These are the specialized attributes*/
    #page-one .margin1 { margin:40px 0 0 0 }
    #page-one .margin2 { margin:24px 30px 0 30px }
    So, will the specified classes always override my defaults? I'm a little concerned some lesser known browser's going to come along and make them all cumulative or something equally stupid.

    I found out, only the other day, that I could #ID up the Body, if I wanted to. This means I can set new defaults for each page... Acceptable practice?

    Sorry if this is a dumb question. I'm going along with how I think CSS works.

    Many thanks,
    Last edited by Doctor_Varney; 11-14-2008 at 12:49 AM.
    Definition: Computer rage is a heightened physiological response with associated feelings of anger and frustration[1] resulting from using a computer or other complex electronic device. It may result in the physical assault of the computer or similar item.[2] Computer use often leads to verbal abuse and occasionally physical violence towards the object.[3] Computer rage may be caused by distress due to a hardware or software problem which the enraged person is unable to correct.

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    margin1 and margin2 are not semantic class names, which is generally encouraged nowadays. Think of what the element actually IS rather than how it's presented.

  • #3
    Regular Coder Doctor_Varney's Avatar
    Join Date
    Mar 2008
    Location
    Midlands, UK
    Posts
    649
    Thanks
    45
    Thanked 29 Times in 28 Posts
    Quote Originally Posted by CyanLight View Post
    margin1 and margin2 are not semantic class names, which is generally encouraged nowadays. Think of what the element actually IS rather than how it's presented.
    The word "margin" has been used for illustrative purposes only.
    Last edited by Doctor_Varney; 11-14-2008 at 02:39 AM.
    Definition: Computer rage is a heightened physiological response with associated feelings of anger and frustration[1] resulting from using a computer or other complex electronic device. It may result in the physical assault of the computer or similar item.[2] Computer use often leads to verbal abuse and occasionally physical violence towards the object.[3] Computer rage may be caused by distress due to a hardware or software problem which the enraged person is unable to correct.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •