我有这个HTML:
.one{
display: inline-block;
width: 80px;
border: 1px solid;
}
.two{
display: inline-block;
width: 100px;
border: 1px solid;
}

<span class="one"> Explanation: </span>
<span class="two">There is some explanation about something. There is some explanation about something</span>
&#13;
如您所见,EXPLANATION
的字词位于.two
框的底部。我怎样才能把它放在最顶端?这是预期的结果:
答案 0 :(得分:2)
vertical-align: top;
救援!
.one{
display: inline-block;
width: 80px;
border: 1px solid;
vertical-align: top;
}
.two{
display: inline-block;
width: 100px;
border: 1px solid;
}
<span class="one"> Explanation: </span>
<span class="two">There is some explanation about something. There is some explanation about something</span>
答案 1 :(得分:2)
垂直对齐属性的默认值为baseline
,这就是为什么第一个跨度可以在基线上查看,因为下一个跨度的高度更大。
要使其在顶部进行查看,您需要将vertical-align
属性设置为顶部:
.one{
display: inline-block;
width: 80px;
border: 1px solid;
vertical-align: top;
}
答案 2 :(得分:1)
span
是inline
元素,默认情况下为vertical-align: baseline
。
添加vertical-align: top
以覆盖它。
.one {
display: inline-block;
width: 80px;
border: 1px solid;
vertical-align: top;
}
.two {
display: inline-block;
width: 100px;
border: 1px solid;
vertical-align: top;
}
<span class="one"> Explanation: </span>
<span class="two">There is some explanation about something. There is some explanation about something</span>
答案 3 :(得分:1)
答案 4 :(得分:1)
默认情况下,所有inline
和inline-block
元素都会根据父元素的baseline
进行对齐。
来自WikiPedia:
基线是大多数字母“坐”的线,下面的下划线延伸。
要解决此问题,您可以vertical-align: top
明确使用display: inline-block
。
.one,
.two {
display: inline-block;
vertical-align: top;
border: 1px solid;
}
.one {
width: 80px;
}
.two {
width: 100px;
}
<span class="one"> Explanation: </span>
<span class="two">There is some explanation about something. There is some explanation about something</span>