Why is it that when I have three boxes in a div without floating them, the outer div wraps around them, but when I add the float, the outer div collapses?
<html>
<head></head>
<body>
<style>
#OuterWrapper {
height: 100%;
width: 200px;
border: 1px BLACK dotted;
text-align: left;
}
.Box {
float: left; // remove this float and the outer wrapper wraps the three boxes
height: 50px;
width: 50px;
background: BLUE;
border: 1px WHITE SOLID;
}
</style>
<div id="OuterWrapper">
<div class="Box"></div>
<div class="Box"></div>
<div class="Box"></div>
</div>
</body>
That is because floating elements doesn’t affect the size of the parent element. You can use the
overflowstyle to make the element contain the children.Also: You should have a
doctypetag so that the page isn’t rendered in Quirks Mode. Yourstyleelement should be in theheadelement. The</html>tag was missing.