我希望標題文本在div中間垂直對齊,目前使用margin-top將其向下推,但當標題較長並溢出時導致不一致到第二行。當div位置爲絕對時,垂直對齊標題:絕對
請在這裏看到的樣品: http://ryconbg.jaffewebsites.com.au/our-company/sustainability-and-energy-efficiency/
HTML
<div id="page-featured" style="background: url(<?php echo $src[0]; ?>) !important; overflow: hidden; background-size: cover !important; background-position: center !important;"></div>
<div id="page-overlay">
<div id="page-titles">
<h1><?php the_title(); ?></h1>
</div>
</div>
CSS
#page-overlay, #page-featured {
height: 400px;
width: 100%;
}
#page-overlay {
position: absolute;
top: 95px;
background-color: rgba(0,0,0,0.1);
z-index: 100;
color: #FFF;
}
#page-titles {
width: 100%;
height: 100%;
text-align: center;
}
#page-titles h1,
#page-titles p {
margin: 0px;
position: absolute;
top: 40%;
left: 0;
right: 0;
}
提前感謝!
對不起,正在修正 - 目前正在按下頂部:40%而不是保證金頂部 –
請** [edit] **您的問題並添加詳細信息。謝謝。 –
爲什麼垂直對齊:中心不工作?你爲什麼要用邊距來居中文本? – RelatedRhymes