0

I don't know how to summarize my situation, but here's the simplified code showing the problem (index.html) :

<html>
   <body>
      <div id="wrapper" class="divide">
          <div id="top" class="divide">
                ....(all of its contents)....
          </div>
          <div id="content" class="divide">
              <div id="left">
                  ....(all the contents)....
               </div>
               <div id="right">
                  ....(all the contents)....
               </div>
           </div>
       </div>
       <div id="footer">
       </div>
    </body>
 </html>

(style.css)

.divide{
   margin-left:auto;
   margin-right:auto;
   width:960px;
 }

 body {
   background-color: #666600;
 }
 #left {
     ......
     ......
     float: left;
 }

  #right {
     ......
     ......
     float: left;
 }

 #wrapper{
    background-color:#ffffff;
  }

So here I want the "wrapper" div background to be white in color, and the body background surrounding it to have another color (in here I put the brownish color). This works for the "top" div, but not the "content" div (thus, all of its children). The "content" div has the same background color as body, which doesn't make sense to me because the "wrapper" div does contain "content" div.

In other word, the "wrapper" div seems doesn't reach the "content" div and all of its children. Is there any workaround for this problem? Inform me if you all need additional information. Thanks for any help!

NOTE: As our helpful people pointed out, the floating properties in the div element does cause the above problem. I did not realize that. That's why I didn't put the floating properties in the first place. So I just edited the above code so that we know what's really causing it. Peace!

vandershraaf
  • 905
  • 3
  • 11
  • 23

3 Answers3

4

Do you have any floated elements, such as #left and #right?

If so, you need to clear your floats.

One way to do that is to add overflow: hidden to #wrapper.

You should also fix a small mistake in your HTML: </left> to </div>.

thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • it wasnt me. i havent checked your solution yet – vandershraaf Jul 29 '11 at 20:06
  • Same..dunno why we got downvoted. +1 to counter :D you had my answer neway, but beat me by a sec – Nick Rolando Jul 29 '11 at 20:08
  • @AlienWebguy: I suspect that he's reduced his CSS down to what he *thinks* is the relevant part, like he's done with his HTML. Look at the names of the `div`s: `left` and `right`. I might be wrong - if I am, I'll remove my answer. – thirtydot Jul 29 '11 at 20:14
  • there was some floating properties in the code. i thought it wasn't really a problem until you guys pointed it out. thanks! – vandershraaf Jul 29 '11 at 20:14
  • @thirtydot hahah i just noticed you answered my very same question: http://stackoverflow.com/questions/5956707/problem-with-div-bg-color-styl-in-ff-chrome good stuff :p – Nick Rolando Jul 29 '11 at 20:42
  • 2
    @Shredder: I answer [lots](http://stackoverflow.com/tags/css/topusers) of CSS questions :) – thirtydot Jul 29 '11 at 20:50
3

If you float your content divs, you might be having a problem with not clearing the floats. Try adding overflow:auto to your wrapper div

Nick Rolando
  • 25,879
  • 13
  • 79
  • 119
0

I put your code into JSFiddle and got this: http://jsfiddle.net/XPLWR/, it looks fine to me.

ayyp
  • 6,590
  • 4
  • 33
  • 47
  • so there should be any other thing causes this? – vandershraaf Jul 29 '11 at 20:01
  • 1
    @vandershraaf Most likely a `float` on one of the `div`s inside the wrapper. If an element is floated it's removed from the regular flow and thus won't cause the wrapper to extend further. One solution would be to add `clear:both;` to your `content` and `header` IDs. – ayyp Jul 29 '11 at 20:05
  • @ Andrew Peacock, you're totally right. i'm still a newbie in this css stuff, so thanks for pointing it out. – vandershraaf Jul 29 '11 at 20:18