22

Ok, so this seems like a really silly problem but I can't get my container div to inherit the height of the floated elements inside of it. Since I need to center the container div, I can't use float to fix this problem. Here is my css:

#container {
margin: 0 auto;
width: 1000px;
border-left: 1px solid #f1f1f1;
border-right: 1px solid #f1f1f1;
border-bottom: 1px solid #f1f1f1;
}

#focus {
padding-left: 23px;
width: 977px;
padding-top: 20px;
padding-bottom: 23px;
border-bottom: 1px solid #f1f1f1;
float: left;
}

.rslider {
float: left;
width: 600px;
margin-left: 15px;
}

.welcome {
float: left;
width: 300px;
}

Html:

<div id="container">
   <div id="logo_block">
   <a href="#"><img src="img/logo.jpg" alt="" /></a>
   </div>
   <div id="focus">
    <div class="welcome">
    <h1>All About This Page</h1>
    <p>Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, liquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.</p>
    </div>
   <div class="rslider">
    <img src="img/slider_image.jpg">
   </div>
   </div>
  </div>

Any ideas?

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Thomas
  • 5,030
  • 20
  • 67
  • 100

1 Answers1

20

You are looking for the so-called clearfix.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • I knew about other methods (like `overflow:hidden` or `float` on wrapper element) which cannot be used in some situations, but this fixed my problem – betatester07 Feb 26 '15 at 22:47