更改span元素的高度

时间:2017-02-17 01:41:07

标签: html

我正在尝试通过将所选文本放在span元素中然后为span设置一个彩色底部边框来实现彩色下划线,例如

border:bottom: 1px solid red;

这样可行,但这句话太过分了: enter image description here

这是整个span元素周围的边框: enter image description here

有没有人看到减少span元素高度的方法,以便底部边框更靠近单词?

由于

2 个答案:

答案 0 :(得分:2)

内联元素没有高度,因此您可以将显示属性更改为inline-block,然后使用line-height属性将边框移近:



span {
  border-bottom: 1px solid red;
  display: inline-block;
  line-height: 10px;
}

Does anyone see a way to <span>reduce</span> the height of the span element so the bottom border is closer to the word?
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您也可以使用身高。

span {
  border-bottom: 1px solid red;
  display: inline-block;
  line-height: 20px;
}
Does anyone see a way to <span>reduce</span> the height of the span element so the bottom border is closer to the word?