web之家  

一、水平居中

需要设置两点:

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

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

代码:

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

 

 

二、DIV垂直居中

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

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

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

posted on 2016-09-02 17:35  路修远而求索  阅读(215)  评论(0编辑  收藏  举报