When doing flexible layouts, there is no way around using relative sizes, so that fonts and elements resize accordingly.
CURRENT RELATIVE UNITS
- EM
Relative to the font-size of the element. The information comes from the browser preset. - REM (not supported in older browsers, like IE 8)
Relative to font-size of the root element
- PERCENT
Relative to the container
CALCULATION
If not set differently, 1 em equals 16 Pixel in most browsers, which gives us a calculation basis.
Preset value = 16PX = 100% or 1EM or 1 REM
So 1/16 = 0,0625 is our calculation factor.
1 2 3 4 5 |
PX EM 1 = 0,0625 12 * 0,0625 = 0,75 48 * 0,0625 = 3 250 * 0,0625 = 15,625 |
EM VS REM
The difference between EM and REM is the inheritance.
The REM value is calculated in reference to the root element, the font size of the HTML, not the BODY, element.
The EM value is calculated in reference to its parent element.
SUPPORT
Due to limited support in older browsers, you can use graceful degradation in your stylesheet to use both.
1 2 3 4 |
li a { font-size:20px; font-size:1.25rem; } |
The Pixel value must be added before the REM value !