2012-03-22 38 views
1

我的代碼已經通過w3school驗證,但它仍然在IE和Firefox中顯示不同。爲什麼我的CSS + HTML網頁在IE和FireFox中的顯示方式不同?

我的連接欄allong頂部似乎在IE中級聯下來,但在Firefox中顯示爲一條直線(應該是)!

我的HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd"> 

<html> 

<head> 

<link rel="stylesheet" type="text/css" href="lbf.css"> 

<title>Love British Film</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

</head> 
<body> 
<div id="main_container">fegerfg 

    <div id="header"> 
    <div class="logo">Love British Film.com </div> 
    </div> 
    <div class="nav_bar"> 
     <ul class="nav_list"> 

     <li class="odd"><a href="index.html">Home</a></li> 
     <li class="even"><a href="index.html">Reviews</a></li> 
     <li class="odd"><a href="index.html">Forums</a></li> 
     <li class="even"><a href="index.html">Videos</a></li> 
     <li class="odd"><a href="index.html" >Downloads</a></li> 
     <li class="even"><a href="index.html">News</a></li> 
     <li class="odd"><a href="index.html" >Fun bits</a></li> 
     <li class="even"><a href="index.html">Contact us</a></li> 
     </ul> 
    </div> 




     <div class="main_text"> 
     <div class="header">HEADER FOR MAIN CONTENT</div> 


     Main content!! 
     </div> 

     <div id="film_of_day">Film of day </div> 




     <div id="poll_of_week">asdnasdljasasdasfdasfasfas</div> 




</div> 
</body> 
</html> 

和我的CSS代碼

body 
{ 
background:url(bg.jpg) no-repeat #FFF center top; 
padding:0; 
font-family:Arial, Helvetica, sans-serif; 
font-size:11px; 
margin:0px auto auto auto; 

} 

div { 
margin: 0px; 
padding: 0px; 
width: 0px; 
} 

#main_container{ 
width:1200px; 
height:auto; 
margin:auto; 
padding:0px; 
} 
#header{ 
position:relative; 
width:1200px; 
height:170px; 
background:url(header.jpg) no-repeat center; 
background-position:0px 0px; 
margin:auto; 
padding:5px; 
} 
.logo{ 
width:auto; 
height:auto; 
font-size:20px; 
position:relative; 
top:80%; 
text-align:right; 
} 
.nav_bar{ 
width:1200px; 
height:50px; 


} 
ul.nav_list{ 
list-style-type:none; float:left; display:block; width:1200px; 
margin:0px; padding:0px; 
} 

ul.nav_list li.odd a{ 
display:block;width:150px; text-align:center; float:left;text-decoration:none; background:url(images/home.png) no-repeat left; 
background-color:rgb(147,216,255);height:40px; line-height:40px; color:rgb(168,100,63); 
} 
ul.nav_list li.even a{ 
display:block;width:150px; text-align:center; float:left;text-decoration:none; background:url(images/home.png) no-repeat left; color:rgb(168,100,63); 
height:40px; line-height:40px;background-color:rgb(26,142,165); 
} 
a.odd:link, a.odd:visited { 
display:block;width:133px; text-align:center; float:left;text-decoration:none; background:url(images/home.png) no-repeat left; } 
ul.nav_list li.even a:hover{background-color:#A29;} 
ul.nav_list li.odd a:hover{background-color:#F99;} 

a.even:link, a.even:visited { 
display:block;width:133px; text-align:center; float:left;height:40px;text-decoration:none; background:url(images/home.png) no-repeat left; color:#676d77;} 
a.even:hover{ 
color:#FFFFFF; 
} 



.header{ 
width:500px; 
text-align:center; 
margin-bottom:50px; 
} 
.main_text{ 
display:inline-block; 
float:left; 
width:600px; 
height:600px; 
background-color:rgb(147,216,255); 
} 

#film_of_day{ 
float:right; 
width:340px; 
height:250px; 
background-color:rgb(147,216,255); 

} 


#poll_of_week{ 
margin-top:50px; 
float:right; 
width:280px; 
height:250px; 
outline:solid; 
padding:1px; 
} 
+7

僅供參考,如果你的代碼已經被「w3school」驗證我會關注... – dougajmcdonald 2012-03-22 15:39:59

+1

@dougajmcdonald上帝,請張貼它作爲答案,所以我可以upvote它: - 史詩! – 2012-03-22 15:41:41

+0

我爲什麼要擔心?我上傳了W3驗證器檢查網站的HTML和CSS文件,並返回了所有綠色和良好的? – 2012-03-23 00:31:30

回答

3

您正在將a標籤懸浮在您的li標籤內,這不是很好的做法並導致您的問題。

你應該浮動的li標籤,並留下您的a標籤未漂內爲紐帶

參見:http://jsfiddle.net/ZmhzA/1/

+0

謝謝你!這排序我的跨瀏覽器問題!現在我只需要檢查我的代碼與其他瀏覽器...再次感謝:) – 2012-03-23 00:38:00

7

歡迎來到真實的世界。
IE和Firefoy解釋CSS彼此不同。這總是一個問題,而且一直會是!如果你想減少不同的行爲或看起來,你可以嘗試使用所謂的CSS重置。

什麼是css重置?
這是一個簡單的css文件,它將每個定位,填充,邊距,默認情況下來自瀏覽器的所有內容重置爲零。所以你可以確保你的大部分樣式都會被解釋爲相同的。當然,它仍然不會一樣,但它可以幫助你把它放在正確的方向。您也可以使用GridLayouts進行定位,這也是一個很好的工具,並且在大多數瀏覽器中看起來都一樣。

而只是一個提示,歌劇,鉻,IE的長輩verions,Safari瀏覽器打開它,你會驚訝它看起來也不同;-)

相關問題