2011-05-01 67 views
1

代碼雲:周邊div標籤不適背景色

<div id="wrapper"> 
    <div id="content"> 
    <!-- content --> 
    </div> 
    <div id="sidebar"> 
    <!-- sidebar --> 
    </div> 
</div> 

我應用background-color爲包裝,但它並不顯示,除非我設置一個固定的高度。爲什麼它會考慮內容和邊欄填充封裝?還有什麼其他方法可以讓background-color在沒有設置固定高度的情況下出現?

+3

#content和#sidebar是否浮動?將#wrapper設置爲「overflow:hidden;'。 – Marwelln 2011-05-01 10:54:19

+1

我們可以看到將背景色應用於包裝的代碼/ css。 – 2011-05-01 10:54:57

+0

是的,請向我們展示#wrapper,#content和#sidebar的CSS。 – Midas 2011-05-01 11:18:59

回答

1

正如有人在評論中說,如果他們的是浮動的(他們是),然後應用overflow: hidden (哪些工作)。

0

什麼其他的方法那裏得到的 背景色顯示時不 設置一個固定的高度是誰?

  • 浮動#wrapper
  • 使用clearfix
  • 請確保您有內容:)
  • 確保#wrapperdisplay:blockinline-block
  • 添加填充

一種方法來檢查,除了Firebug,設置border:1px solid red,看看如果你得到一個2px的或者你看到了你所期望的邊框。如果你看到正常的邊框,還有一個問題:發佈CSS的時間。

這裏有一個快速和骯髒的clearfix你可以嘗試,現在,看是否能幫助:

<div id="wrapper"> 
    <div id="content"> 
    <!-- content --> 
    </div> 
    <div id="sidebar"> 
    <!-- sidebar --> 
    </div> 
    <br style="display:block;clear:both;width:100%" /> 
</div>