CSS Tutorial – 11 – Units


When it comes to setting the size of a property
we have several alternatives. First, there are absolute units of length, which should
look the same at any screen resolution. These are common units of length, namely centimeter
(cm), millimeter (mm) and inches (in). We also have two typographical units. Points
(pt) and Picas (pc). By definition, there are 72 points to an inch and 12 points to
one pica. Next, we have the relative units of length.
Pixels (px), which are the small squares that build up your screen, and percentage (%)
which is relative to the current value of the property where it is used.
We also have em-height (em) and x-height (ex), which are two more typographical measures.
Em-height is the same as the font-size and x-height is about half the font-size. If we compare the units we can see that pixels,
points, and millimeters are really small units, and that inch is the largest. Also one em-height
and 100% percent both gives the current font-size. It’s possible to set the length using decimals.
Some properties even allow negative values for length.
Another thing to note is that a rule won’t work if we include a space before the unit.
Same thing if we forget to type any unit. Whenever a CSS rule contains an error it will
be ignored by the browser.

Add a Comment

Your email address will not be published. Required fields are marked *