默认 HTML 字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24542508/
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 02:10:12  来源:igfitidea点击:

Default HTML font size

htmlcss

提问by Romain Braun

I wonder what the default html font-size is and I can't find the answer.

我想知道默认的 html 字体大小是多少,但我找不到答案。

What I mean is this :

我的意思是:

What is the font size in pixels corresponding to this :

与此对应的字体大小(以像素为单位)是多少:

html {
    font-size: 100%;
}

It could be useful to know this if you need to calculate rem font sizes.

如果您需要计算 rem 字体大小,了解这一点可能会很有用。

回答by Dryden Long

The default is 16px.

默认值为 16px。

If you create an HTML file with any text in it, open it in Chrome, you can check the computed styles.

如果您创建一个包含任何文本的 HTML 文件,请在 Chrome 中打开它,您可以检查计算出的样式。

enter image description here

在此处输入图片说明

回答by ubomb

In the W3 CSS specification, there is no definite default font-sizeother than the relative value medium.

W3 CSS 规范中font-size除了相对值之外没有明确的默认值medium

That being said, a quick test with the developer versions of IE, Firefox, and Chrome all show that the de facto standard is 16px. I would be interested to see someone test this on mobile versions.

话虽如此,对 IE、Firefox 和 Chrome 的开发人员版本的快速测试都表明事实上的标准是 16px。我很想看到有人在移动版本上测试这个。

Edit: As of 2017-03-20, the stable versions of Chrome, Firefox, Edge, and IE on the desktop as well as Chrome, Firefox, and Opera on mobile all default to the de facto standard of 16px for font-size.

编辑:截至 2017 年 3 月 20 日,桌面版 Chrome、Firefox、Edge 和 IE 以及移动版 Chrome、Firefox 和 Opera 的稳定版本均默认为font-size.

回答by CMPS

Live demo

现场演示

Here's an easy way to check it:

这是一个简单的检查方法:

HTML:

HTML:

<p>Hello world</p>
<span></span>

JQuery:

查询:

$('span').text("Font-size is: "+($('p').css('font-size')));

Output on Screen:

屏幕输出:

Hello world

Font-size is: 16px

回答by Jukka K. Korpela

The default is browser-dependent. This is actually the very reason to using the remunit. If we knew that the default is, for example, 16px, there would be little point in using rem.

默认值取决于浏览器。这实际上是使用该rem装置的真正原因。例如,如果我们知道默认值是 ,16px那么使用rem.

As other answers describe, the common factory settingdefault in browsers is 16px. This can be changed by the user, in browser settings. In some browsers, you can set the size to any number in pixels, whereas some browsers have just a few alternatives, described verbally. In addition, the default font size can also be set in a user style sheet.

正如其他答案所描述的那样,浏览器中的常见出厂设置默认值为16px. 这可以由用户在浏览器设置中更改。在某些浏览器中,您可以将大小设置为以像素为单位的任意数字,而某些浏览器只有几种选择,如口头描述。此外,还可以在用户样式表中设置默认字体大小。