我有一个名为带下划线的类:
<style>
.underlined {
border-bottom: 1px dotted blue;
}
</style>
但是比较此类的span
和div
时,文本和笔画之间的间隙大小不同:
<span class="underlined">underlined text</span><br>
<br>
<div class="underlined">underlined text</div>
我试图在带下划线的中添加一些行(我希望它保留在baseline grid中):
<style>
.underlined {
border-bottom: 1px dotted blue;
margin: 0px;
padding: 0px;
outline: 0px;
outline-offset: 0px;
box-sizing: border-box;
height: 21px; /* which is the whole body's line height*/
}
</style>
它现在仍在基准网格中,但是差距仍然不一样。 :(
有人有主意吗?
非常感谢您!
答案 0 :(得分:0)
您的问题可能会发生,因为默认情况下div
标签具有display: block
,而span
标签具有display: inline
。为了避免这种情况,只需将display: block
类添加到您的.underlined
类中即可。
.underlined {
border-bottom: 1px dotted blue;
}
span.underlined {
display: inline-block;
}
<span class="underlined">underlined text</span><br>
<br>
<div class="underlined">underlined text</div>
答案 1 :(得分:0)
span
标签是一个内联元素,这意味着您无法为其设置高度,
为了使其正常工作,请向display:inline-block
类添加display:block
或underline
.underlined {
border-bottom: 1px dotted blue;
margin: 0px;
padding: 0px;
outline: 0px;
outline-offset: 0px;
box-sizing: border-box;
height: 21px; /* which is the whole body's line height*/
display: inline-block;
}
<span class="underlined">underlined text</span><br>
<br>
<div class="underlined">underlined text</div>
答案 2 :(得分:0)
两个元素都需要应用display:inline-block;
。然后,线高问题将得到解决。
.underlined {
border-bottom: 1px dotted blue;
margin: 0px;
padding: 0px;
outline: 0px;
outline-offset: 0px;
box-sizing: border-box;
height: 21px; /* which is the whole body's line height*/
display:inline-block;
background-color:#ccc;
}
div.underlined {
width:100%;
}
<span class="underlined">underlined text</span><br>
<br>
<div class="underlined">underlined text</div>
https://jsfiddle.net/Sampath_Madhuranga/aLurpoxy/6/
这对您有用。尝试一下,让我知道是否有任何问题。 谢谢。