Thursday, 22 January 2015

Lengths and percentages in CSS


There are many property specific units for values used in CSS, but there are some general units that are used in a number of properties.

em
em is unit for the calculated size of a font. For example:
font-size:2em;
Here 2em, is two times the current font size.

px
px is unit for pixels. For example:
font-size:20px; 

pt
pt is unit for points. For example:
font-size:20pt; 

%
% is unit for percentage. For example:
font-size:20%;

Other units include pc(picas), cm(centimetres), mm(millimetres) and in(inches).

When a value is zero, you need not to state a unit.

It is generally accepted that 'em' or '%' are the best units to use for font-sizes, rather than 'px', which leads to non-resizable text in most browsers.

No comments:

Post a Comment