[英]Why doesn't this html/css work in ie?
我只是想在頁面上將div居中。 它在chrome中有效,但在div中仍在左側:
<html>
<head></head>
<body>
<div id="container" style="margin:0 auto; width:200px;">
test
</div>
</body>
</html>
我讀過的所有內容都說過,要使一個塊元素居中,只需添加margin:0 auto
並指定一個寬度,所以我不知道為什么這不起作用。
我正在IE 7.0.5730上進行測試
您的HTML代碼段沒有DOCTYPE
, 因此IE默認為quirksmode 。
使用HTML5文檔類型:
<!DOCTYPE HTML>
<html>
<head></head>
<body>
<div id="container" style="margin:0 auto; width:200px;">
test
</div>
</body>
</html>
另一種方法是在您的CSS中執行此操作,無論ie是否處於quirksmode,這種方式都可以工作:
body{text-align:center;}
#container{text-align: left;}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.