gpt4 book ai didi

字体大小为 62.5% 的 html 和 em 计算

转载 作者:太空狗 更新时间:2023-10-29 16:06:52 25 4
gpt4 key购买 nike

我有点困惑,希望有人能解释这种行为!?

我有以下代码:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>test</title>
<style>

html{
font-size: 62.5%; // set the base font-size to 10px
}

body{
background-color: red;
}

@media only screen and ( max-width: 100em ) /* 1000px?? */ {

body{
background-color: green;
}

}

</style>
</head>
<body>

</body>
</html>

如果视口(viewport)小于 1001 像素,我认为 body 的背景色应该从红色切换到绿色。但这是行不通的。颜色在 1600px 处变化。所以看起来 font-size: 62.5% 不起作用!?问题是:为什么?

最佳答案

来自CSS Media Queries Spec

Relative units in media queries are based on the initial value, which means that units are never based on results of declarations. For example, in HTML, the ‘em’ unit is relative to the initial value of ‘font-size’.

关于字体大小为 62.5% 的 html 和 em 计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24171958/

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