我正在尝试将第一个div垂直对齐到浏览器的中心,并将其下面的所有内容都放在该div之下。
我可以将这两个div包裹在另一个div中,并使该div居中,但我不能更改此html结构,而只能用两个div来实现。第一个div是一个动态容器,将在其中显示不同的html。第二个div是静态的。
.center {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
<div class="center">
I'm at the center of the Browser!
</div>
<div>I'm just below the center!</div>
如果浏览器支持视口单位,则可以使用以下方式:
.center {
position: relative;
left: 0;
margin-top:50vh;
}
看到它的工作原理:http : //jsfiddle.net/fgpqkrr4/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句