I have a div tag which has some background color, that adds good look to my page. The div tag contains a button which when clicked generates two textboxes. Everything is working properly but the background is not expanding as and when new elements are added dynamically. I used height:auto in the div tag styling. How do i achieve background expansion as and when content gets added to the page dynamically?
1 Answer
Assuming that you are not using absolute positioning on your child elements, all you have to do is set overflow:hidden on the parent, this will ensure that the parent expands around all the children inside.
7 Comments
Ruan Mendes
Interesting... I don't follow why overflow:hidden would cause the background color to stay in sync with a growing div. jsfiddle.net/sqf8w/1 doesn't require anything special to make the div grow. Were you able to reproduce the problem?
Martin Jespersen
@juan: when you tell the parent to hide every thing that overflows, and at the same time doesn't tell the parent to have an exact size, the parent is forced to make sure nothing overflows, and thus it expands to accommodate all children.
nikhil
setting overflow:hidden solved my problem.I am posting my code in jsfiddle.net/nikhilneela/cTPSa, Please tell me whether the way i have done styling is proper or not. I want to refine my code
Ruan Mendes
@nikhil, I don't see the problem, what is the button we should click to get text boxes to show up? @Martin: The jsfiddle that I posted shows that setting
overflow:hidden is not required, at least for a simple example. Do you know in which cases overflow: hidden fixes a problem?nikhil
@Juan Mendes: Must click add to dynamically generate text boxes
|
height:100%? Also if possible , put up some code or a working demo at jsfiddle.net