[英]Center a div in ie7 and ie8
我想簡單地將div居中在窗口中間。 目前正在使用
.notSupported { display: block; position: fixed; top: 0; bottom: 0; left: 0; right: 0; max-width: 500px; max-height: 200px; margin: auto; background-color: #f3f3f3; z-index: 1000; text-align: center; }
<div class="notSupported">Your browser is not supported</div>
在ie7
它導致div出現在左上角,並在ie8
居中。
html, body { height: 100%; } #wrapper { position: relative; width: 100%; height: 100%; display: table; } #middle { display: table-cell; vertical-align: middle; text-align: center; } /* for IE7 and below */ #middle { *position: absolute; *top: 50%; *width: 100%; *text-align: center; } #center { *position: relative; *top: -50%; }
<div id="wrapper"> <div id="middle"> <div id="center">Center me !</div> </div> </div>
阻止在IE7中不起作用。
您必須使用zoom:1並將其作為hack阻止,或者僅將ie7作為其他css的hack來阻止。
.notSupported {
display: block;
*display: block;
*zoom:1;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
max-width: 500px;
max-height: 200px;
margin: auto;
background-color: #f3f3f3;
z-index: 1000;
text-align: center;
width:200px;
height:50px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.