...

View Full Version : Safe use of class to override margin default?



Doctor_Varney
11-13-2008, 11:02 PM
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:


<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:


/*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,
http://i183.photobucket.com/albums/x103/Doctor_Varney/signature.gif

Apostropartheid
11-13-2008, 11:32 PM
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.

Doctor_Varney
11-14-2008, 12:48 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum