【发布时间】:2014-05-10 01:13:20
【问题描述】:
我将一些溢出的文本水平居中(实际上我是在堆栈溢出时发现的)。我试图将其垂直居中无济于事。
HTML:
<div id="outer"><div id="inner"><div id="text">some text that will overflow</div></div></div>
这是 CSS:
#outer {
display: block;
position: relative;
left: 100px;
width: 100px;
border: 1px solid black;
background-color: silver;
height: 150px;
}
#inner {
/* shrink-to-fit width */
display: inline-block;
position: relative;
/* shift left edge of text to center */
left: 50%;
}
#text {
/* shift left edge of text half distance to left */
margin-left: -50%;
/* text should all be on one line */
white-space: nowrap;
}
我在这里有一个改编的小提琴: http://jsfiddle.net/HfT72/
有人有什么想法吗?
【问题讨论】: