让DIV居中

方法一:
====css=========
.box {
position:absolute;
width:500px;
height:200px;
left:50%;
top:50%;
margin-top:-100px;
margin-left:-250px;
background:#f60;
}

=====xhtml=====

<div class=”box”> </div>

方法二:
==========css==============

div {width:100%;}
#box {display:table;height:550px;_position:relative;overflow:hidden;}
#box div{_position:absolute;_top:50%;display:table-cell;vertical-align:middle;}
#box div div
{width:100%;background:#f7f7f7;display:block;_position:relative;_top:-50%;}
#box div div .bgRed

{background:red;height:50px;width:210px;margin:0 auto;}

======xhtml===============
<div id=”box”>
<div><div>
<p class=”bgRed”>111</p>
</div></div>
</div>

Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]