gpt4 book ai didi

css - REM 总是来自 html 中的字体大小吗?

转载 作者:行者123 更新时间:2023-11-28 12:40:53 25 4
gpt4 key购买 nike

假设我有:

html {
font-size: 20px;
padding: 8px;
}

div {
font-size: 0.5rem;
padding: 0.5rem;
}

div 中的内边距是 4px(因此来自 html{} 中的 padding)还是 10px(形成 font-size in html{})?

最佳答案

CSS Values and Unites Module Level 3状态:

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.

您可以通过检查您的 div 元素并查看计算值来自己尝试:

html {
font-size: 20px;
padding: 8px;
}

div {
font-size: 0.5rem;
padding: 0.5rem;
}
<div>Hello, world!</div>

Example

是的,正如我们所见,padding 已计算为 10px - font-size 的一半。

关于css - REM 总是来自 html 中的字体大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26483986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com