我有一個父容器(如彈出),其中我有附加到父容器的子元素。子元素是一個有一些文本的div。我想將文本居中放置在div中,以便文本保持居中對齊在子div中,但文本應該在垂直方向上自對齊,因爲它長到3-4行以上。我可以隨着文字的增長垂直對齊文本,但是當它仍然是一個小文本時,它應該是垂直居中,這不會發生。我已經在子類中嘗試了很多CSS屬性。 任何幫助都會很好。定心文本垂直,因爲它生長,在子類
.parentclass {
position: absolute;
top: 110px;
left: 165px;
width: 470px;
height: 260px;
text-align: center;
background-image: url(../images/Notification_BG.png); }
.childclass {
position: relative;
position: inherit;
width: 430px;
height: 192px;
left: 50%;
top: 50%;
margin-left: -215px;
margin-top: -96px; /* Negative half of height. */
text-align: center;
text-overflow: -o-ellipsis-lastline;
border: 1px solid blue;
font-family: Arial;
font-size: 28px;
color: white; }
感謝 KK
嘗試變換https://developer.mozilla.org/en-US/docs/CSS/transform –