9

When I expand comment body that is floated to right my container does not expand with it. How can I fix this?

Better explanation: http://jsfiddle.net/5fmpp/

Stan
  • 25,744
  • 53
  • 164
  • 242
  • Parent containers never expand to contain floated elements without additional CSS properties. – Rob Jul 31 '11 at 15:29

3 Answers3

24

Add overflow: hidden to the container so it can contain the float:

.comment
{
    width: 960px;
    margin: auto;
    margin-top: 24px;
    font-size: 14px;
    background-color: #777777;
    overflow: hidden;
}
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
2

Check this out.

You need to clear the float at the end of the comment box

Ahmad Alfy
  • 13,107
  • 6
  • 65
  • 99
  • 1
    Shouldn't it rather be style="clear: both;" instead of clear="both"? – MazeChaZer May 14 '14 at 19:42
  • 1
    Using clear as an HTML attribute is deprecated and has been for years. Use the solution proposed by @MazeChaZer instead. See the clear attribute reference [here](http://www.sitepoint.com/web-foundations/clear-html-attribute/) – Simon Robb Sep 16 '14 at 14:32
0

The modern way to solve this would be to add display: flow-root; to the container in order to establish a new block formatting context.

overflow: hidden also establishes a new block formatting context but with its obvious side effects.

Robbendebiene
  • 4,215
  • 3
  • 28
  • 35