2012-03-12 90 views
0

我有一個內聯列表,我試圖去「填充」它的div的整個寬度。css內聯列表邊距

如果我在列表中使用了一個margin-right,最後一個元素將不會到達div的末尾(因爲它有正確的邊距),或者右邊距會強制它在下一行超過div的寬度。

這裏是我所描述的例子。

http://i.imgur.com/9CJx7.png

我的html:

<div id="footerstick" style="background:url(site_files/bg_shears.png) repeat-x; "> 
    <div id="footer_wrap"> 
     <div id="footer_top_shelf"> 
      <ul> 
       <li>Contact Us</li> 
       <li>FAQ</li> 
       <li>About Us</li> 
       <li>Distribution</li> 
      </ul> 
     </div> 
    </div> 

</div> 

我的CSS:

#footerstick { 
    position: relative; 
    margin-top: -230px; /* negative value of footer height */ 
    height: 230px; 
    clear:both; 
    } 
#footer_wrap {width:980px; margin:auto;}  
#footer_top_shelf {height:70px; overflow:hidden; } 
#footer_top_shelf ul li {display:inline; list-style:none; color:#c7c7c7; font-size:30px; margin-right:85px; line-height:75px; text-transform:uppercase; font-family:myriad pro; } 
+0

你的問題是什麼? – Madbreaks 2012-03-12 04:02:01

+0

如何讓第一個列表元素完全位於左側,最後一個元素位於右側。我不認爲我想要使用第n個孩子選擇器,因爲它不與舊版的broswers兼容嗎? – Sackling 2012-03-12 04:23:56

回答

0

這樣寫:

#footer_top_shelf ul li + li{ 
    margin-left:85px; 
} 
+0

加號是做什麼的?這似乎並不奏效我只是將最後一個列表元素全部刪除。 – Sackling 2012-03-12 04:26:02

+0

'+'符號是「鄰接兄弟選擇器」它具有以下語法:E1 + E2,其中E2是選擇器的主題。如果E1和E2在文檔樹中共享同一個父節點,並且E1緊接在E2之前,則選擇器匹配,忽略非元素節點(如文本節點和註釋)。 – ityler22 2012-03-12 05:38:18

0

嘗試下面的CSS - 看到你的圖像後爲根據您的要求如果我得到你的問題正確,這個更新的CSS應該可以幫助你。

#footerstick { 
    position: relative; 
    margin-top: -230px; /* negative value of footer height */ 
    height: 230px; 
    clear:both; 
    } 
#footer_wrap {width:980px; margin:auto;}  
#footer_top_shelf {height:70px; overflow:hidden;} 

#footer_top_shelf ul 
{ 
    margin:0; 
    padding:0; 
    text-align:center; 
} 

#footer_top_shelf ul li { 
display:inline; 
list-style:none; 
color:#c7c7c7; 
font-size:30px; 
margin:0px 40px; 
line-height:75px; 
text-transform:uppercase; 
font-family:myriad pro; 
} 

注意:您可以顯示你的實時代碼,所以我們可以很容易地找出如何你的代碼工作,在那裏你所面臨的問題。

+0

這是很好..不完全是我試圖完成。因爲第一個元素上有一個左邊距,將其從左側移開,最後一個元素的右邊距將其從右側移開。另一方面,這可能是好的,也許我想的不是很好看.. – Sackling 2012-03-12 14:00:58