Expand the div to contain absolutely positioned content.

I have a div that contains a bunch of absolutely positioned controls. These controls are dynamically generated, and I want the div to expand, so it will span all content both in width and in height. How can I do this in CSS?

+6
source share
2 answers

If I understand correctly, you can write like this:

.parent{ position:relative; width:100px; height:100px; } .dynamicDiv{ position:absolute; top:0; bottom:0; left:0; right:0; } 
+2
source

This is hard to achieve. When you have a relative parent with absolute children inside, they cannot influence the size of the parent div.

You should also use relatives. Why are the controls located absolutely?

But when CSS doesn't work, JavaScript comes to the rescue. So it can be solved.

+2
source

Source: https://habr.com/ru/post/924101/


All Articles