html - 如何使行高与字体高度匹配?

标签 html css

我试过将行高设置为 1em,但是,字体上下仍有一些空间(大约 3px):

enter image description here

如何将网站的行高设置为与字体高度完全一致?

JSFiddle:http://jsfiddle.net/uovjzrn6/1/

HTML:

Hello, world!

CSS:

body {
    font-size: 18px;
    line-height: 1em;
}

最佳答案

引用以下示例 div HTML5/CSS3:

HTML

<div id = "sample">
    Hello, world!
</div>

CSS

body {
    font-size: 18px;
    padding:0;
    margin:0;
}
#sample
{
    height: 18px;
    line-height: 18px;
    background-color: #e0e0e0;
    margin-top:-3px;
}

希望这可能有所帮助。

关于html - 如何使行高与字体高度匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30722224/

相关文章:

html - 网格布局模式的第 n 个子选择器

javascript - 数学函数不起作用

javascript - 导航 : Setting page Anchor tag (javascript or css)

html - 使用 html 标签将首字母下沉

html - 如何在 CSS 中使用 "all"属性

html - Groovy/Grails Hibernate 无法创建 bean 事务

html - 仅限 CSS - 带有滚动条的动态标题高度和 100% 内容高度

javascript - 通过Web应用程序获取设备物理身份

html - 具有固定宽度列的 Flexbox 中的 2x2 网格

css - Bootstrap 3 中的嵌套列