Link to home
Start Free TrialLog in
Avatar of LuluDev
LuluDev

asked on

When to use px vs em vs in ...on a margin property?

I am confused on when to use em or px when setting margin property on elements. For font settings I have been told that em is best to use as a general rule. But I see for margins a common setting seems to be in pixels (px). How do I determine whether I should use px or em for a margin? Is there a general rule for margin unit of measurement choices (px, em, in)?
ASKER CERTIFIED SOLUTION
Avatar of VoteyDisciple
VoteyDisciple

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VoteyDisciple
VoteyDisciple

Sorry, I was referring to the typographic use of "em" in which M and the font size are the same thing; it's true there are plenty of modern fonts that do not include M and then that obviously won't be true.  For normal fonts they should be equivalent.

Sorry for any confusion.
Avatar of LuluDev

ASKER

Thank-you for your responses and clarifications.
http://www.w3.org/TR/CSS21/syndata.html#value-def-length
I guess you got it mixed up with "ex", which is equivalent to the height of a lower case "x".
Typography can be confusing.

http://en.wikipedia.org/wiki/Em_%28typography%29#Incorrect.2FAlternate_Definitions
<< One em is sometimes said to be equal to the WIDTH of a capital "M". >>
Anyway, it's easier to simply think of it as the font-size of the current element without any other reference.
This does not change much for this particular question...

I agree with the rest of your first post.  People use "px" because they don't know better.  Just like people design fixed-width pages because they don't know how to code a liquid layout properly.

Actually, for font-size, i prefer to use percentages.  The result is exactly the same (font-size:1.5em is equivalent to font-size:150%).  Percentages just make more sense to me.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial