如何设置DIV水平、垂直居中

一、水平居中

需要设置两点:

1  设置DIV 的width属性即宽度。

2  设置div的margin-left和margin-right属性即可

代码:

<div style="800px; margin-left:auto; margin-right:auto; color:White; height:400px">DIV居中</div>

二、DIV垂直居中

同样的道理,需要设置两点:

1  设置DIV 的height属性即宽度。

2  设置div的margin-top和margin-bottom属性值为auto即可

原文地址:https://www.cnblogs.com/keyi/p/5834300.html