What's the difference between CSS “em” and “rem”?
1) Learning Web Design Book by Jennifer Niederst Robbins
1 rem= 1* browser's default font size
1 em= depends on the element type, for h1 it's something, for h2, it's sth else.
2) https://css-tricks.com/confused-rem-em/
>While em is relative to the font-size of its direct or nearest parent, rem is only relative to the html (root) font-size.
I get the rem part, but not the em part. What does it mean?
3) https://blog.logrocket.com/using-em-vs-rem-css/#:~:text=Let%27s%20get%20started!-,What%20are%20em%20and%20rem%20and%20why%20use%20them%3F,relative%20to%20a%20set%20value.
I've read this as well but since I'm only knowing html and starting to learn css, I could not get most of the things written there.
4) https://www.youtube.com/watch?v=tlRLEsZa89M
I watch this short video. It does makes things somewhat clear about "inherits from parent".
Anyway, I am eager to learn the crux of "em". Maybe with some code examples, or figures(if it's lying anywhere in internet)
2 comments
[ 4.3 ms ] story [ 18.1 ms ] threadYou can put those properties which should vary in ems and then all you have to do is change the large and small font sizes from the default. Margin, however, remains in rems because it needs to be consistent. Everything will scale proportionately and your large and small button classes are clear, expressive, and concise.
https://codepen.io/LukeAtWork/pen/gOzNdRo
The "current font size" is determined by lookup up the hierarchy to the nearest parent element with a specified font size, ending with the `html` element which will reflect the browser's default font size if nothing else has been set.