CSS 为什么字体大小不会改变?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15858511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:21:15  来源:igfitidea点击:

Why font size does not change?

cssfont-sizeem

提问by hiway

I want to set font size with em, not px. Here is my code:

我想用 设置字体大小em,而不是px。这是我的代码:

<style type="text/css">
body{
    font-size: 62.5%;
}

div{
    font-size: 1.2em;
}
</style>

<body>
<div>hello world</div>
</body>

I want to set divfont size to be 12px, but it looks small than I expect, I disable divstyle with chrome browser tools, it does not look to have any change. Why and how should I do to make divfont size 12px? Thanks.

我想将div字体大小设置为 12px,但它看起来比我预期的要小,我div使用 chrome 浏览器工具禁用了样式,它看起来没有任何变化。为什么以及我应该怎么做才能使div字体大小为 12px?谢谢。

采纳答案by Michael Nguyen

hmm, seems to work for me: example

嗯,似乎对我有用:例如

Though, what you might be referring to is littlechange from enabling/disabling the font-sizeproperty. This is because the emfor nested elements is relative to their parents font-size. In your instance, the font-size:Xemfor the div is relative to the font-size:X%of the body.

不过,您可能指的是启用/禁用该属性的变化很小font-size。这是因为emfor 嵌套元素是相对于它们的父元素的font-size。在你的例子中,font-size:Xemdiv 是相对于font-size:X%身体的。

If your still getting no change, try setting your body's font-sizeto a larger percentage to make your div's font larger

如果您仍然没有变化,请尝试将您的body'sfont-size设置为更大的百分比以使您的div's 字体更大