我试图获得类似于基准的垂直对齐,但在文本的第一行而不是最后一行。 top
和text-top
都没有得到正确的对齐方式。有任何想法吗?谢谢!基线垂直对齐,但在顶部
编辑:这假定字体大小在被对齐的元素中是相同的。在接受的答案上查看@FelipeAls的评论。
编辑:现在的代码示例和图片:
我试图做的是垂直对齐文本中几个inline-block的元素,使它们的基线都在相同的位置。我宁愿不使用边距和填充来推挤事物,因为我发现每当我这样做时,我最终都会与不同的浏览器一起玩鼹鼠。
HTML:
<div class="foo">
<span>one</span>
<span>two two two two</span>
<span>three three three three three three three three three</span>
<button type="button">action</button>
</div>
<div class="bar">
<span>one</span>
<span>two two two two</span>
<span>three three three three three three three three three</span>
<button type="button">action</button>
</div>
CSS:
body {
font-family: sans-serif;
font-size: 12px;
}
button {
font-family: inherit;
font-size: inherit;
}
div {
position: relative;
width: 500px;
text-align: center;
}
div.foo, div.bar {
margin-bottom: 2em;
}
div span {
text-align: center;
}
div.foo span {
display: inline-block;
width: 50px;
vertical-align: top;
}
div.bar span {
display: inline-block;
width: 50px;
vertical-align: baseline;
}
div button {
display: inline-block;
width: 125px;
}
见http://jsfiddle.net/don01001100/3t8v5L1j/3/。
请包括代码示例,而不是代码的链接。更具体一点:你想与什么元素保持一致? –
@Jonathan,对不起!我已经添加了相关的HTML和CSS。 jsfiddle中有一些额外的代码,但我在这里放的是相关的。 –
谢谢。这有帮助。 –