1

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?

5
  • did u try height:100% ? Also if possible , put up some code or a working demo at jsfiddle.net Commented Mar 3, 2011 at 8:20
  • tried use display:none; and display:block; (or inline) Commented Mar 3, 2011 at 8:22
  • I think that this is not enough information to write a proper answer. Maybe you can paste some code to pastebin, so we can examine it. Commented Mar 3, 2011 at 8:26
  • can you post your code on jsfiddle.com or something? There are many things that might be wrong here. What's your overflow set to? Are you floating any of your divs? Do you give them explicit width. It should be too difficult to solve this Commented Mar 3, 2011 at 8:28
  • 1
    Here's a jsfiddle that proves that the simple case as described does not reproduce the problem. jsfiddle.net/sqf8w/2 OP needs to create a fiddle that reproduces the problem. Commented Mar 3, 2011 at 8:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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?
@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.
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
@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?
@Juan Mendes: Must click add to dynamically generate text boxes
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.