简体   繁体   English

Google Chrome开发者工具显示浏览器默认字体大小为18像素吗?

[英]Google Chrome Developer tools shows browser default font size as 18 pixels?

The default font size is known to be 16 pixels. 默认字体大小已知为16像素。 I made a simple page and tested this out. 我做了一个简单的页面并进行了测试。 I looked at the Developer Tools in Google Chrome and it says 18 (yes I removed margin and padding to the paragraph element). 我查看了Google Chrome浏览器中的开发人员工具,显示为18(是的,我删除了margin和padding到段落元素)。 I ran the following JavaScript to manually get the font size to see if it was 16px and it was. 我运行以下JavaScript来手动获取字体大小,以查看它是否为16px。 What is this number 18 from? 这个数字18是什么来的?

 var el = document.getElementById('hello'); var style = window.getComputedStyle(el, null).getPropertyValue('font-size'); var fontSize = parseFloat(style); console.log(fontSize); 
 <p id='hello'>Hello world</p> 

在此处输入图片说明

The line-height . line-height Set line-height: 1; 设置line-height: 1; and the height will be 16px. 高度为16像素。

 var el = document.getElementById('hello'); el.style.lineHeight = '1'; var style = window.getComputedStyle(el, null).getPropertyValue('font-size'); var fontSize = parseFloat(style); console.log(fontSize); 
 <p id='hello'>Hello world</p> 

The area selected by the Chrome Dev Tools includes the line-height (see https://developer.mozilla.org/en/docs/Web/CSS/line-height ), and any padding / margin around the p element. Chrome开发者工具选择的区域包括line-height (请参阅https://developer.mozilla.org/en/docs/Web/CSS/line-height )以及p元素周围的任何padding / margin

  • You can explore the padding and margin in the styles pane: 您可以在样式窗格中浏览填充和边距:

    在此处输入图片说明

  • If there is no padding or margin (as in your example), then this is simply the line-height . 如果没有填充或边距(如您的示例中所示),则仅是line-height Set it to 1 to get your expected output. 将其设置为1以获得预期的输出。

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

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