I'm trying to place 2 divs side by side inside of another div, so that I can have 2 columns of text and the outer div drawing a border around both of them:
HTML
<div id="outer"> <div id="left"> ... <div id="right"> </div>
CSS
#outer{ background-color:rgba(255,255,255,.5); width:800px; } #left{ float:left; } #right{ width:500px; float:right; }
However, the outer div registers a height of 0px and so the border doesn't go around the other divs. How do I make the outer div recognize the heights of the things inside it?
The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.
Height = 0 because the parent of the elements have 0 height, so make sure your parent, which is body here have 100% height or else.
Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.
height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.
It's not because the floating divs doesn't have a height, it's because the floating divs don't affect the size of the parent element.
You can use the overflow
style to make the parent element take the floating elements in consideration:
#outer { overflow: auto; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With