How to make a parent div grow with its children?

前端 未结 5 957
盖世英雄少女心
盖世英雄少女心 2020-12-30 00:49

How do I make a parent/container DIV grow as more children DIV\'s are added.

5条回答
  •  孤独总比滥情好
    2020-12-30 01:22

    The only reason why your parent div would not grow with its content is if it's content is absolute positioned or is using floats, in the former case there is nothing you can do short of resizing it with javascript, in the latter you can put the following code at the end of your floating elements:


    So say both the child elements in your example have a float, the code would look like this

    ** CONTENT GOES HERE **
    ** CONTENT GOES HERE **

    You can use any node, as long as you use "clear: both" on it (So

    would work too).

提交回复
热议问题