We have a CSS file with some rules similar to the following:
.directory-result ul
{
margin-top: 20px;
width: 60em;
}
.about-text
{
margin-top: 1em;
margin-bottom: 1em;
}
Everything is working ok, but we’re wondering specifically about the inconsistencies between the margin-top values. One is 20px and the other is 1em.
Which is the best one to go with? What are the points I should consider when deciding which to use? Thanks.
emunits are used for better scalability of the page when the size of the elements depend on the page’s scale. It’s especially important for old browsers (e.g. IE6) and mobile platforms.pxunits are used for absolute values, whileemis relative to the font size of the particular element.1emmeans one font-line, e.g. you have a box with font-size12pxthat means that 1em will be equal to12pxAlso, using
pxseems easier because you know the exact value, butemunits inherit the value of their container.In this case, the first
<p>will have font-size equal to the basic font-size * 1.2, and the second<p>will display with font-size * 1.2 * 1.2.