My question is a duplicate of this question, but I will need a pure CSS solution for this and cannot use JS to fix it. So here are my questions:
- Why doesn't wrapper expand although it is absolute positioned and should not be limited to its parent?
- Why does it exactly fit the parent?! It shouldn't expand at all if there is a problem with floated children!
CSS:
#parent{
position: relative;
height: 200px;
width: 60px;
background: red;
}
#wrapper{
background: blue;
position: absolute;
top: 0;
left: 0;
}
#wrapper > div{
float: left;
width: 30px;
background: yellow;
margin: 1px;
}
HTML:
<div id='parent'>
<div id='wrapper'>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</div>
Here is the JSiddle demo.