1

I have the following code:

<!doctype html>
<html>
<head>
  <style type="text/css">
    #left {
      float: left;
    }

    #left_top, #left_bottom {
      height: 50%; /* Not working... */
    }

    #right {
      float: left;
    }
  </style>
</head>
<body>
<div id="wrapper">
  <div id="left">
    <div id="left_top">A</div>
    <div id="left_bottom">B</div>
  </div>
  <div id="right">
    Content
    <br />
    Content
    <br />
    Content
  </div>
</div>
</body>
</html>

The two DIVs with the IDs left_top and left_bottom should take up 50% of the height of the surrounding DIV (#left). How can I make that happen?

Thanks and regards!

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
Daniel
  • 2,409
  • 2
  • 26
  • 42

1 Answers1

0

You are assuming left is the same height as content, however this isnt how floated divs work.

You can see this in effect here.

One way would be to give both left and right the same specified height.

The alternative, for a more flexible layout would be to use CSS tables, and not floats:

Demo Fiddle

CSS

#wrapper {
    display:table;
    height:0%; /* to provide a base 'autofit' height */
}
#left, #right {
    display:table-cell;
}
#left_top, #left_bottom {
    height: 50%;
}
SW4
  • 69,876
  • 20
  • 132
  • 137