CSS margin: 0 & margin: 0px ??

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

CSS margin: 0 & margin: 0px ??

Post by nigma »

Hey, anyone know the diff between:

Code: Select all

margin: 0px;
And:

Code: Select all

margin: 0;
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Nigma,

There is no difference. There are a few different measurements in css, like px(pixels), pt(points), like there are in the real world(centimeter and inch for example), but 0 cm or 0 inch is still nothing.

So with 0 it isn't necesary to give a measurement.

Greetz Jolly.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Doesn't margin default to 0? Why would someone put margin: 0 when it is by default set to that?
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

i don't thing the margins are default set to 0px, for example in frames they are like 5px or something like that...
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

Cruzado_Mainfrm is correct. All browsers have different margins that they set by default for the html < body > < / body > tag.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Also they might be overiding something - for example by defining an inline style to overide a custom tag.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Excellent guys, thanks a bunch!
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Use 0px. If you try to validate your pages, they may not validate without a unit accompanying each measurement. It's just good practice to get into.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

I tend to base a lot of my CSS style off of examples from Jeffrey Zeldman's site. He uses 0 rather than 0px, so I use 0.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

I'm surprised to hear that. Zeldman's usually got it all figured out. Maybe 0 is an exception to the rule, but if you try to validate any other measurement without a unit, it won't work.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Yes, it seems to be the only case where he does it. But as jollyjumper said above, 0 cm is the same as 0 px, etc, so no unit is necessary I suppose.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Oh well. My point still stands: it's good practice to ALWAYS put a unit after your declarations.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I actually just bought his book a few days ago.
Post Reply