Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS difference between 0 and 0em

Tags:

css

Is there any difference between

margin: 0;

and

margin: 0em;

I didn't notice anything, but my teacher keeps telling me that it's not the same.

like image 555
Jakub Arnold Avatar asked Jun 01 '09 14:06

Jakub Arnold


People also ask

What is 0em in CSS?

0 and 0em are the same, but any value other than 0 for x and xem are not the same. Follow this answer to receive notifications.

What is the difference between px and in CSS?

The px belongs to the absolute category of length units whereas the em and %(percentage) refers to the relative class of sizing units. The value of px is fixed over the HTML document but the em and %(percentage) depends on the unit used by the parent element.


2 Answers

The file is bigger with 0em.


The way to prove to your professor that there is no difference is to set something to 0 and something else to 0em and inspect the DOM with Firebug or a similar tool. If I recall correctly, you'll see that both are now 0. So the only difference is in the source. (But it's been a while since I checked. I might be thinking of getting and setting styles from jQuery. So check it out before you take my word.)

like image 36
Nosredna Avatar answered Oct 12 '22 07:10

Nosredna


There's no difference when the value is 0. If it were 1 and 1em, yes, there's a difference, but 0 is 0, no matter the unit.

like image 52
Chris Doggett Avatar answered Oct 12 '22 09:10

Chris Doggett