天天看點

關于IE6中無法使用margin:0 auto居中的問題終極解決方案

本人剛開始學CSS的時候也遇到過這類問題,網上搜尋出來的答案大部分都是使用

text-align:center
           

屬性,其實最簡單的方法就是在html檔案開始處添加doctype如下,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
           

這樣子IE6下使用margin就能正常居中了。

新手可以在自己的文本編輯器裡面添加帶doctype的html模闆,這樣子友善以後使用。下面貼出我editplus裡面的html模闆:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge" /><!-- 防止IE8,7進入怪異模式 -->
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><!-- 設定編碼	 -->
  <meta name="generator" content="" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
 </head>

 <body>
  
 </body>
</html>