ajhsu / blog

The external storage of my brain.
3 stars 0 forks source link

CSS relative units #88

Open ajhsu opened 5 years ago

ajhsu commented 5 years ago

Disclaimer: I literally copy-pasted one of the paragraph from MDN below.

em

em: 1em is the same as the font-size of the current element. The default base font-size given to web pages by web browsers before CSS styling is applied is 16 pixels, which means the computed value of 1em is 16 pixels for an element by default. But beware — font sizes are inherited by elements from their parents, so if different font sizes have been set on parent elements, the pixel equivalent of an em can start to become complicated. Don't worry too much about this for now — we'll cover inheritance and font-sizing in more detail in later articles and modules. em are the most common relative unit you'll use in web development.

rem

rem: The rem (root em) works in exactly the same way as the em, except that it will always equal the size of the default base font-size; inherited font sizes will have no effect, so this sounds like a much better option than em, although rems don't work in older versions of Internet Explorer (see more about cross-browser support in Debugging CSS).

vw, vh

vw, vh: Respectively these are 1/100th of the width of the viewport, and 1/100th of the height of the viewport. Again, these are not as widely supported as em.