By Noxxxx from https://interview.noxxxx.com/?post_type=post&p=6 上山打老虎
欢迎分享与聚合,尊重版权,可以联系授权
rem、em、vw、vh
- em:Relative to the parent element 相对于父元素
- rem: Relative to the root element (HTML tag) 相对于根元素
- %: Relative to the parent element
- VW: Relative to the viewport’s width
- VH: Relative to the viewport’s height
- 1vw = 1% of viewport width
- 1vh = 1% of viewport height
- 1vmin = 1vw or 1vh, whichever is smaller
- 1vmax = 1vw or 1vh, whichever is larger
em
em | 在 font-size 中使用是相对于父元素的字体大小,在其他属性中使用是相对于自身的字体大小,如 width |
ex | 字符“x”的高度 |
ch | 数字“0”的宽度 |
rem | 根元素的字体大小 |
lh | 元素的 line-height |
vw | 视窗宽度的 1% |
vh | 视窗高度的 1% |
vmin | 视窗较小尺寸的 1% |
vmax | 视图大尺寸的 1% |
See the Pen css – em 的实际效果 by hjoker (@hjoker) on CodePen.