我在製作動態幻燈片。在文本框中保留文本片段
我正在嘗試獲取一些我動態分配的文本,以便在盒子中居中對齊和垂直對齊。
到目前爲止,我有:
HTML
<body>
<div class="slide">
<span class="content">
<b>Hello. This text needs to be:</b><br><br>
- left-aligned but <br>
- centered in the grey box<br>
- even if it changes<br>
- the center of the white box <br>
should equal center of grey one.
</span>
</div>
</body>
CSS
.slide {
position:relative;
background-color: #ddd;
width: 300px;
height: 300px
}
.content {
position: absolute;
top: 30%;
left: 15%;
background-color: #fff;
}
輸出
這並不是因爲如果工作文字發生變化,它不再是中心。任何人有任何想法如何解決這個問題?
http://jsbin.com/uyiFiwI/23/edit
所以'.slide'始終是300x300像素? –
嗨,你爲什麼不使用'overflow:scroll;'屬性。如果你不想這樣做,那麼你可以考慮使用'font-size:.8em;'!但第一種選擇更好。第二個可能是愚蠢的。 –
是的幻燈片總是300 x 300.希望如果只有少量的文字,它會在中間打耳光。感謝下面的答案。雖然非常接近,但它們並不在那裏。 –