【发布时间】:2018-04-25 16:32:45
【问题描述】:
我目前面临将多个位置垂直对齐的问题:绝对 div 到中间。虽然我应用了宽度:100% 和高度:100%,但元素似乎也溢出了。请帮我解决这个问题。谢谢。
<div class="wrapper">
<div class="wrapper-inner">
<div class="section-1">
<h2>Heading Here</h2>
<p>Some text here</p>
</div>
<div class="section-2">
<p>Another text here.</p>
<p>One more time.</p>
</div>
</div>
</div>
html,
body {
width: 100%;
height: 100%;
}
.wrapper {
width: 100%;
height: 100%;
}
.wrapper-inner {
width: 100%;
height: 100%;
position: relative;
}
.section-1 {
position: absolute;
left: 20vw;
width: 40vw;
background: #ccc;
}
.section-2 {
position: absolute;
left: 60vw;
background: #375642;
width: 40vw;
}
演示:https://codepen.io/rae0724/pen/jamzbX
除了 top:50% 和减去它的高度外,我找不到在当前位置和中间位置制作这些内容的方法,但不利于响应。
【问题讨论】:
-
你所需要的只是节类相对于屏幕高度垂直对齐到中间,对吗?