margin:auto 就可以水平居中,那么垂直居中怎么办? 谢谢
------解决方案--------------------
有多种情形,请参考http://dudo.org/archives/2008060122236.html。
如果是固定尺寸,可以这样:
- CSS code
<style> #warp { position: absolute; width:500px; height:200px; left:50%; top:50%; margin-left:-250px; margin-top:-100px; border: solid 3px red; } </style>
------解决方案--------------------
------解决方案--------------------
最外层加个table就好办了。
------解决方案--------------------
加table?
------解决方案--------------------
- HTML code
<!DOCTYPE HTML> <html lang=""> <head> <meta charset="gbk"> <title></title> <style type="text/css"> body {padding: 0; margin: 0;} body,html{height: 100%;} #outer {height: 100%; overflow: hidden; position: relative;width: 100%; background:ivory;} #outer[id] {display: table; position: static;} #middle {position: absolute; top: 50%;} /* for explorer only*/ #middle[id] {display: table-cell; vertical-align: middle; position: static;} #inner {position: relative; top: -50%;width: 400px;margin: 0 auto;} /* for explorer only */ div.greenBorder {border: 1px solid green; background-color: ivory;} </style> </head> <body> <div id="outer"> <div id="middle"> <div id="inner" class="greenBorder"> </div> </div> </div> </body> </html>
------解决方案--------------------
------解决方案--------------------
<style>
#warp {
position: absolute;
width:500px;
height:200px;
left:50%;
top:50%;
margin-left:-250px;
margin-top:-100px;
border: solid 3px red;
}
</style>
------解决方案--------------------
margin:0 auto;
不就行了吗。
------解决方案--------------------
vertical-align:middle;
或
.align-center{
position:fixed;
left:50%;
top:50%;
margin-left:width/2;
margin-top:height/2;
}
------解决方案--------------------
同上 +1
------解决方案--------------------
正解。