I know there are a hundred and one questions about autosizing a div’s height but no suggestions seem to work for me which leads me to believe I’m missing something obvious. Basically I have a container Div, then another smaller div inside (absolutely positioned) and in side that one I have X about of div boxes being created (relatively positioned). The problem is that the height of the main container div won’t stretch with it. Any help? Thanks!
.mainContainer{
position: relative;
width:800px;
height:auto;
padding-top:10px;
margin-left: auto;
margin-right: auto;
border-style:solid;
border-width:2px;
}
.smallerDivInsideMainDiv{
position:absolute;
left: 20px;
top: 50px;
width: 600px;
}
.divsThatAreOverflowing{
position: relative;
margin-top:20px;
border-style:solid;
border-width:1px;
}
From what I know, you can’t have an absolutely positioned element inside a relatively positioned element and attempt to have the parent height adjust to the absolute child. If you’re only using it for positioning with left and right, use margins instead.
Here the parent is dark grey, and smaller div inside is light grey, with the overflowing div as red. When it changes height, both of it’s containers will adjust.