我昨天和今天花费了无数个小时来弄清楚如何做到这一点。我简直不敢相信CSS没有一个简单的方法来处理这个问题。
本质上,我有一些文本在 span class="name" 中,它的长度不是固定的。在某些情况下,它可能会溢出到下一行。如何在我的容器内垂直对齐它呢?
更具体地说,在我的容器内如何垂直对齐 "ABC Father And Sons Company LLC"? http://jsfiddle.net/D3L8S/
<div class="container">
<span class="name">ABC Father And Sons Company LLC </span>
<a href="#" class="addr">Address</a>
<a href="#" class="hours">Hours</a>
<a href="#" class="more">More</a>
</div>
CSS类
// CSS
.container {
background: #DDEBF0;
padding: 11px;
border: 1px solid #D2D2D2;
width: 380px;
margin-bottom: 10px;
height:18px;
line-height:18px;
display:inline-block;
}
.name {
width:200px;
float:left;
}
.addr, .hours, .more {
width:60px;
float:left;
}
如果我给“name”添加一个负的上边距(margin-top:-8px),我就可以实现这个效果,但显然会破坏XYZ公司有限责任公司的呈现 http://jsfiddle.net/FM4dA/ 最好的解决方案应该是跨浏览器兼容的(至少ie8应该支持)
编辑-我最初忘记提到我的容器宽度是固定的,无法更改。