DIV 浮动层 绝对定位居中浮动 用CSS怎么写 —— 绯色的CSS系列

DIV浮动层绝对居中定位用CSS怎么写?详细解说,直接看样式,下面的写法兼容IE系列浏览器和火狐浏览器。

 

DIV浮动层绝对居中定位用CSS怎么写?下面的写法兼容IE系列浏览器和火狐浏览器。

详细解说,直接看样式:

 1 div.center-absolute{
 2     width:300px;
 3     height:300px;
 4     display:block; 
 5     position: absolute;
 6     top:50%;
 7     left:50%;
 8     margin-left:-150px;
 9     margin-top:-150px;
10 }

 

 width:300px;height:300px; DIV总的有个宽高吧,根据你的具体情况设置;

display:block; 把  被修饰的区块  以块级元素显示;

 position: absolute;top:50%;left:50%;margin-left:-150px; margin-top:-150px; 这一段时重点,我想聪明的朋友都看明白了。
就是绝对定位DIV层,当然你应该让他相对于body标签。margin-left:-300px; 这个值是DIV宽度的一半, margin-top:-150px; 是DIV高度的一半。

查看 DIV浮动层绝对居中定位用CSS怎么写? 的演示。

懒人建站 整理

本文链接:DIV浮动层绝对居中定位用CSS怎么写?http://www.51xuediannao.com/html+css/htmlcssjq/cssjueduijuzhong.html
posted @ 2015-09-07 17:05  浅浅浅红莉栖  阅读(174)  评论(0编辑  收藏  举报