2011-02-02 40 views
0

這是我的CSS代碼:爲什麼在ie中,右側是絕對定位的標誌?

#header { 
    width: 900px; 
    margin-left: 0; 
    position: relative; 
    text-align: left; 
    clear: left; 
    float: left; 
} 
#logo { 
    z-index:-1; 
    position:absolute; 
} 

和HTML ...

<div style="text-align: center;"> 
    <div id="wrapper"> 
     <div id="header"> 
      <!--Logo--> 
      <div id="logo"> <a href="http://projectstratos.com/" title="Home"><img src="logo-transparent.png" border="0"></a> 
      </div> 
      <!--End Logo--> 
     </div> 
    </div> 
</div> 

該標誌需要保持絕對的,在我的內容。在Firefox中它看起來不錯,但是在標誌是在右邊而不是在左邊。我正在使用中心div,而不是使用居中保證金方法,因爲它不起作用!

如何將它移動到左側?

+0

哪個版本的IE?您的代碼適用於Chrome和IE8。 http://jsfiddle.net/mattball/uhBMR/ – 2011-02-02 18:03:38

+1

你不能只用`left:0`嗎? – Marnix 2011-02-02 18:05:00

回答

0

如果需要從中心偏移,你知道標誌的寬度,那麼你可以設置寬度,設置留到50%,而使用負邊緣到中心了。然後,一旦居中,您可以添加到邊距以獲取您想要從中心獲得的偏移量。

實施例:



#logo { 
    position:absolute; 
    left:50%; 

    margin-left:-250px; /* This negative margin gets the logo in the centre */ 
    /* Adjust this value to get the offset you want. If you want to have it 100px to the left make it -350px, if you want it 50px to the right make it -200px */ 

    width:200px; 
    z-index:-1; 
} 

0

你可以試試頂部和左側?

#logo { 
    top: 5px; 
    left: 20px; 
    z-index:-1; 
    position:absolute; 
} 
相關問題