html - 分配 line-height 以跨越 html 中的元素 buggy ?

标签 html css

在这个 fiddle 中 http://jsfiddle.net/qhsnX/3/你可以看到我只为 span 元素分配了 100px 行高,但这也为 span 元素之后的文本提供了相同的行高。相同的代码:

#titleBox {
  margin: 0 auto;
  width: 350px;
  background-color: #6da662;
  height: 100px;
  color: #fff;
  font-size: 16.5px;
  font-weight: bold;
}
span {
  line-height: 100px;
}
<div id="titleBox"> <span>I have 100px line height. || </span> I have 0 line height</div>

不仅如此,我无法更改第一个元素之后的其他跨度元素的行高。 http://jsfiddle.net/qhsnX/4/

#titleBox {
  margin: 0 auto;
  width: 350px;
  background-color: #6da662;
  height: 100px;
  color: #fff;
  font-size: 16.5px;
  font-weight: bold;
}
#one {
  line-height: 100px;
}
#two {
  line-height: 10px;
  color: black;
}
<div id="titleBox"> <span id="one">I have 100px line height. || </span>  <span id="two">I have 10px line height </span>
</div>

这是html语言的bug吗?

最佳答案

行高用于表示行间距,应用于 block 元素,不适用于行内元素。您可以将 span 更改为 div 或者可以在 css 中使用“display:inline-block” 属性

关于html - 分配 line-height 以跨越 html 中的元素 buggy ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37156157/

相关文章:

HTML 电子邮件问题

javascript - 我无法查看数据类型的所有元素

html - 让主栏包裹一个漂浮在侧栏中的超大元素?

javascript - CSS,JavaScript : random image loader with array removes the first part of my variable how to fix this?

javascript - 具有任意区域(有进度)的饼图动画,无闪光灯

css - 为什么我的页面内容本身会向左移动?

html - firebug 在文档类型中返回语法错误?

javascript - 使用 javascript 指定要在数字字段中输入的数字范围

html - 带有响应文本的响应图像

html - 使用 CSS 设置样式 - float 删除样式