gpt4 book ai didi

css - rem 不输出相对于 body 字体的值,em 工作正常

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:35 25 4
gpt4 key购买 nike

我有以下部分,我需要大约 85px 的顶部填充和底部填充。

所以我的部分如下所示:

enter image description here

我的 body 元素的 font-size16px,因此我将以下样式应用于填充部分:

.careers-highlight-contact-section {
padding-top: 5.31rem;
padding-bottom: 5.31rem;
}

我得到 5.31 的方式是 85/16,但现在当我检查计算值时,我看到 padding top 和 padding bottom 实际上是 53px。它是如何得出这个值的?

您可以在此链接上看到此错误 here .

如果您将填充值从 rem 更改为 em,那么您将获得正确的高度。为什么会这样?

enter image description here

最佳答案

如果您引用 W3C 规范,rem单位定义为:

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.

因此,根据我的评论,rem它的计算基于在根元素上声明的字体大小,即 <html>元素而不是 <body>元素。只要申报font-size: 16px在前者上,您会看到将计算出正确的填充。

关于css - rem 不输出相对于 body 字体的值,em 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45613844/

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