2011-07-04 28 views
0

我想一個div中心對齊的圖像。中心對齊旁邊的一個浮動

<div class="header"> 

    <img class="logo" href="x"/> 

    <ul class="topLinks"> 
    <li>blah</li> 
    </ul> 

</div> 

我有「topLinks」ul漂浮在右邊。我想相關的標識類中心到整個940px頁面。我能居中標誌的唯一方法是使用HTML屬性「ALIGN =‘中心’」(我知道這是不建議使用),但它只是相對於浮動排名靠前,而不是整個頁面居中。

我試圖讓圖像是在940px容器的中心,而其排名靠前的鏈接直接漂到它的右側。

回答

2

CSS嘗試:

.header img.logo { 
    margin:auto; 
    clear:both; 
} 

.ul_wrapper { 
    width:100%; 
    height:auto; 
    position:absolute; 
} 

.ul_wrapper ul.topLinks { 
    float:right; 
} 

HTML嘗試:

<div class="header"> 
    <img class="logo" src="x" /> 
    <div class="ul_wrapper"> 
     <ul class="topLinks"> 
      <li>blah</li> 
     </ul> 
    </div> 
</div>