2011-02-02 35 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; 
} 
相关问题