編輯您的標記:
<div style="display:table;" class="metaboxdet">
<div style="display:table-cell;vertical-align:middle;" class="metd">
<div style="margin-left:auto;margin-right:auto;">
<h1>Hello World!</h1>
</div>
</div>
</div>
和你的css是unchang編輯您可以刪除不需要的CSS:
.metaboxdet {
height: 100%;
width: 100%;
position: absolute;
right: 0;
top: 0;
z-index:9;
text-align:center;
margin:0px auto;
background-color: #292484;
background-image: linear-gradient(135deg, #292484, #dc4225);
opacity: 0.6;
}
.metd {position:relative; margin:0px auto; width:70%; }
.metd h1 {color: #FFF; font-size:40px; font-style:italic; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); line-height:1.2em;}
或檢查這個我已經編輯你搗鼓這個
https://jsfiddle.net/fvueL00n/2/
,如果你不希望有額外的div你可以對齊h1
直接在div
以及
更多參考howtocenterincss.com
[這](http://stackoverflow.com/questions/7 273338 /如何垂直對齊圖像裏面的div)應該有助於垂直對齊。 – Kiril