This question already has answers here:
Vertically centering a div inside another div [duplicate]
(24个答案)
4年前关闭。
如何在
http://jsfiddle.net/0j5e06mt/
HTML:
CSS:
资料来源:http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
(24个答案)
4年前关闭。
如何在
caption
中将caption-wrap
div垂直居中放置?http://jsfiddle.net/0j5e06mt/
HTML:
<div class="caption-wrap">
<div class="caption">
<p>test</p>
<p>test</p>
</div>
</div>
CSS:
.caption-wrap {background:red;height:120px;width:100%}
.caption {background:blue;text-align:center}
最佳答案
尝试:
.caption{
position: relative;
top: 50%;
transform: translateY(-50%);
}
资料来源:http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
关于html - 在父div内垂直对齐div? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28573336/