html元素上的font-size:100%有什么作用? [英] What does font-size: 100% on the html element do?
问题描述
我正在开始一个新项目.我问自己:为什么在使用 em
单元时,为什么要在 html
元素上添加 font-size:100%
?
I am in the process to start a new project. I am asking myself: Why should I add font-size: 100%
on the html
element when I am using the em
unit anyway?
与代码相比,此代码 100%
是什么-100%?
What does this 100%
to - 100% compared to what?
推荐答案
对于浏览器,有很多类型将字体大小声明为相同的值.
There are many types of declaring the font-size as the same value for the browser.
-
字体大小:1em;
字体大小:100%;
字体大小:16px;//这是默认设置
这样,您可以获得默认的字体大小.但是请注意,16 px会更改字体大小,但是 em
和%
将取决于body标签中使用的字体大小.
This way, you can get the default font-size. But note that 16 px will alter the font-size, however em
and %
will depend on the font-size used in the body tag.
提琴: http://jsfiddle.net/afzaal_ahmad_zeeshan/5Wkus/
所以您会看到,em完全取决于 body
中声明的字体.或者您可以说,它从孩子到父母.它一直在寻找最接近的父级中的字体大小更改.在大多数情况下,这会将代码定向到body元素或用户代理默认样式表.
So you'll see, em depends totally on the font-declared in body
. Or you can say, it runs from child to parent. It keeps looking for the font-size change in the nearest parent. Which in most cases directs the code to the body element or the user agent default stylesheet.
这篇关于html元素上的font-size:100%有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!