PDA

View Full Version : Bad CSS practice?



Moshambi
11-24-2007, 11:12 AM
so i like the idea of using <div> elements with the id attribute in them to help design a good look to the layout. this is going to be hard to explain without a code example so look at these first:

CSS:


#menu
{
margin-top: xx;
margin-left: xx;
}

#content
{
margin-top: xx;
margin-left: xx;
}



HTML:


<div id="menu">
//some sort of menu items here (i.e. navigation)
</div>

<div id="content">
//content of the site in this area
</div>


now what my question is, where i provide xx for the margins is it bad practice to place a negative number for this value?

i just want to check before i start doing it, because i find it to come in handy, but i am still a noob so any responses will be cool. thanks

Twey
11-24-2007, 11:45 AM
Nope, not bad practice at all, it's quite common and there's nothing wrong with it.

jscheuer1
11-24-2007, 02:00 PM
Well, a negative number is bad practice. But a negative value is fine. The difference being that, a negative number like -2 would be invalid. But a negative value like -2px would be fine.

Moshambi
11-24-2007, 08:15 PM
ok cool thanks. i was hoping you guys would say it isnt because i find it very useful to set up pages that way...although one other question would be is, does the negative value work the same on all browsers etc.?

Twey
11-24-2007, 08:26 PM
Yep, it's supported by the spec and its implementation is pretty much universal.

jscheuer1
11-24-2007, 08:35 PM
To the extent that margins work the same in all browsers, yes. It is usually the default margins on some elements that vary in some browsers. If you explicitly set all margins, differences should be minimal, if any.

The only main exception being (there could be others), in IE the 'box model' is different so variations might emerge because of that. When that happens (or when specifying every margin explicitly isn't practical), conditional comments may be used to set specific styles for IE only.

Moshambi
11-24-2007, 09:56 PM
awesome. thanks again for the help