我的浏览器宽度是 1440px,我想制作一个比浏览器屏幕宽度小一点的元素。所以只比 1440px 小一点。
谁能给我解释一下像素与 rem 的关系?我的浏览器如何决定 rem 单位中的像素数?
最佳答案
Can someone explain to me the way pixels relate to rem? How does my browser decide the number of pixels in a rem unit?
rem
代表 root-em,它是根元素的字体大小。在 HTML 中,根元素是 <html>
. UA 通常应用 font-size
的 16px
至 html
, 因此 1rem
将等于 16px
在那种情况下。
5.1.1. Font-relative lengths: the ‘em’, ‘ex’, ‘ch’, ‘rem’ units
Aside from ‘rem’ (which refers to the font-size of the root element), the font-relative lengths refer to the font metrics of the element on which they are used [...]
rem unit
Equal to the computed value of ‘font-size’ on the root element.When specified on the ‘font-size’ property of the root element, the ‘rem’ units refer to the property's initial value.
以及 font-size
的初始值是medium
.
关于css - 我的应用程序使用 rem 值。我如何将其与像素联系起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26689637/