我想使用CSS在元素中間對齊一些文本。這是我的標記:垂直對齊跨越兩行的元素的文本問題
<div id="testimonial">
<span class="quote">Some random text that spans two lines</span>
</div>
和相關的CSS:
#testimonial {
background: url('images/testimonial.png') no-repeat;
width: 898px;
height: 138px;
margin: 0 auto;
margin-top: 10px;
text-align: center;
padding: 0px 30px 0px 30px;
}
.quote {
font-size: 32px;
font-family: "Times New Roman", Verdanna, Arial, sans-serif;
vertical-align: middle;
font-style: italic;
color: #676767;
text-shadow: 1px 1px #e7e7e7;
}
通常得到.quote
在#testimonial
豎直中間,我會做:
.quote { line-height: 138px; }
但是這打破了佈局,因爲.quote
中的文字跨越多條線。
正如你所看到的,我試過做vertical-align: middle;
,這也不起作用。
任何幫助表示讚賞。乾杯。
可能重複([如何垂直對齊文本?] http://stackoverflow.com/questions/2826681/how-to-align-text-vertically) – Ryan 2011-05-30 19:29:07
不,李', ne-height'在這種情況下不起作用,因爲我的文本不止一行。 – Josh 2011-05-30 19:30:39
@minitech:這不是一個很好的重複。接受的答案是使用'line-height',這對多行不適用。 'display:table-cell'答案在那裏,但沒有解釋,也沒有upvotes。 – thirtydot 2011-05-30 19:31:11