0

I'm designing a wordpress theme from scratch. I used boxes for posts - two posts per row. The CSS code is:

#box  {
margin-bottom:10px;
margin-left:0;
margin-right:10px;
width:240px;
}
.left {
float:left;
margin-left:10px;
}

and there's wrapper to wrap all boxes in page:

#wrapper{
     width:980px;
     background-color:#fff;

}

<div id="wrapper">
<div id="box" class="left">
...WP tags and...
</div>
</div>

so all boxes are in the wrapper. Now the problem is wrapper doesn't show up - no white background on the page, but as soon as i remove float property wrapper come into the play. How can I fix that!?

Mehdi
  • 13
  • 1
  • 11

3 Answers3

1

The boxes are "floating" on top of the wrapper. Simply add clear:both; to #wrapper. Oh and by the way, you don't need to create 3 element for your margin, you can write it on one line, like that margin:0 10px 10px 0; (top, right, bottom, left) Also a little trick you should use when debugging css, add border:solid 1px red; so you can see what you are doing.

Alexcp
  • 348
  • 1
  • 6
  • clearing both didn't work. Margins r in one line firebug shows them separately. i already tested border with firebug, wrapper is before boxes, on top, a very narrow horizontal line – Mehdi Apr 13 '11 at 19:24
1

Give the wrapper element overflow: hidden.

#wrapper{
    overflow: hidden;
    width:980px;
    background-color:#fff;
}

It is the accepted method of making this work across all browsers. It works better and with less hassle than the clearfix workaround.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

You will need a clearfix http://www.webtoolkit.info/css-clearfix.html

Rochester Oliveira
  • 1,443
  • 1
  • 11
  • 10