Lijo Lijo - 7 months ago 8
Javascript Question

Parent Div does not adjust height when adding div dynamically

I am adding divs dynamically as shown in http://jsfiddle.net/Lijo/ZkLg6/5/.

The parent #mainHolder div is not increasing its width when child elements are added – as a result the children breaks the parent div. How can we overcome this by adjusting the parent div height?

enter image description here

Answer

Add overflow:auto

#mainHolder
{
    width: 400px;
    border-top: 3px solid orange;
    border-bottom: 3px solid red;
    border-left: 3px solid purple;
    border-right: 3px solid pink;
    height:auto; overflow:auto
}

Demo here http://jsfiddle.net/ZkLg6/11/

Comments