html - 为什么 Firefox 和 Chrome 中的行高不同?

标签 html css google-chrome firefox

我根据 Matthew Pennell 的解决方案(codepen by CSS Tricks)创建了多行填充文本。在 Chrome 中,一切看起来都很好,但在 Firefox 中,span 元素的高度大于其祖先的高度。如果我为 Firefox 调整垂直填充,在 Chrome 中也会出现同样的问题,反之亦然。

firefox-chrome-bug

为什么会这样?这个问题的真正技术原因是什么?

HTML 代码:

<div class="padded-multiline">
  <h1>
    <strong>How do I add padding to subsequent lines of an inline text element?</strong>
  </h1>
</div>

CSS 代码:

:root {
    font-family: Arial, sans-serif;
    font-size: 20px;
}
.padded-multiline { 
  line-height: 1.3; 
  padding: 2px 0; 
  border-left: 20px solid #c0c;
  width: 400px;
  margin: 20px auto;
}
.padded-multiline h1 { 
  background-color: #c0c;
  padding: 4px 0;
  color: #fff; 
  display: inline;
  margin: 0; 
}
.padded-multiline h1 strong { 
  position: relative;
  left: -10px; 
}

最佳答案

设置一个 line-height: 1; 强将解决这个问题也阅读我的评论。

关于html - 为什么 Firefox 和 Chrome 中的行高不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42003353/

相关文章:

javascript - 媒体上的导航无法获得 100% 的宽度

google-chrome - 下载适用于 Linux 的旧版 Google Chrome

javascript - ASP MVC 中的自定义是/否单选按钮

javascript - 由javascript函数生成的自动增量li标签

html - 如何使用css将html div保持在固定位置?

css - 隐藏 Google Chrome 中的日历图标

google-chrome - 检测另一个浏览器选项卡是否正在使用语音识别

javascript - Electron 选择带有文本输入和 onclick 事件的目录

c# - 在按键事件中将 TextBox 对齐到页面中间

javascript - 如何根据我所在的页面突出显示导航栏