简体   繁体   English

在HTML中添加字体大小会覆盖我所有的字体大小

[英]Adding font-size to HTML overrides all my font-sizes

I font weird behavior if I added font-size to html 如果我在HTML中添加了font-size,我的字体行为就很奇怪

 html {
            font-size: 10px;
        }

it will override all font-sizes I have on all html tags and it will make them smaller 它将覆盖所有ht​​ml标签上所有的字体大小,并使它们变小

I want to keep the font-size on html but I have one div that I won't it to be effected by html font size 我想保持html上的字体大小,但是我有一个div,我不会受html字体大小的影响

Here an example 这是一个例子

https://jsfiddle.net/Ldgworje/1/ https://jsfiddle.net/Ldgworje/1/

try to remove the html from CSS and try 尝试从CSS删除html并尝试

I want to keep the font-size for html but I have one div that I don't want it to be effected by html font size 我想保留html的字体大小,但我有一个div,我不希望它受html字体大小的影响

as you see in the example 如您在示例中看到的

I hope you can help 希望你能帮忙

This is happening because you are using rem for the font size. 发生这种情况是因为您使用rem作为字体大小。 rem and em are supposed to work that way. rem和em应该是这样工作的。 Check https://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/ 检查https://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/

If you do not want rating to be affected use px instead. 如果您不希望评级受到影响,请改用px。

What you do is you add a rule after that html font rule, and you create an ID for that div and you set font size to whatever: 您要做的是该html字体规则之后添加一个规则,并为该div创建一个ID,然后将字体大小设置为任意值:

html {
    font-size: 10px;
}

div#fontSize {
    font-size: 14px; /*Or whatever size you want*/
}

If you want to leave the font size the same as the default for the div element, then just set it to 1em , as below: 如果要使字体大小与div元素的默认大小相同,则只需将其设置为1em ,如下所示:

div#fontSize {
    font-size: 1em; /*Sets this size to 16px, which is default*/
}

Simple! 简单! Just ask if you need any help/explanations/fiddles. 只要问您是否需要任何帮助/解释/小提琴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM