2012-06-12 30 views
0

在我的網站,我有一個搜索結果表。它在Firefox和Chrome中對齊,但不包含IE9。我使用以下條件CSS,但顯然它不工作,它仍然左對齊在IE9中。有條件的CSS爲IE9不工作

<!--[if IE 9]> 
<style type="text/css"> 
.ie9fix { 
    width: 75%; 
    position: absolute; 
    margin-left: auto; 
    margin-right: auto; 
    float: center; 
} 
</style> 
<![endif]--> 

究竟需要更改我的代碼才能使表中心對齊?

+0

這是工作時,你拿出條件? –

+0

只要刪除'位置:絕對'..它真的很奇怪,你的代碼需要IE9的修復 - 該瀏覽器處理CSS相當不錯,實際上 –

+0

'float:center'?你確定這是正確的CSS? – zneak

回答

0

如果你真的需要絕對定位:

<style> 
.example {position: absolute; left: 0; top: 0; width: 100%; } 
.example > DIV {margin: 0 auto; width: 75%; } 
</style> 

<div class="example"><div> 
    ... 
</div></div> 

這應該跨瀏覽器的一致性,而不需要解決IE9 speficically。

+0

我仍然會給內部div一個課程或ID,但否則這就是要走的路。 – user1337

+0

@ user1337 IE6通常目前無關緊要,因此不需要嵌套元素的額外類或id。 –

+0

它不是專門針對IE6支持,而是針對性能和最佳實踐。 – user1337