Resize parent div to match absolutly positioned child div height

后端 未结 3 901
礼貌的吻别
礼貌的吻别 2020-12-20 07:01

I have a CSS problem:

I have an absolute positioned div in a container. The container won\'t resize to the height of the content. Why?

3条回答
  •  余生分开走
    2020-12-20 07:38

    Because when you give absolute position to something, you take it out of the layout flow. This means that its dimensions are no longer used to calculate its parent's height, among everything else.

    If your element has a known fixed height, then you can give an appropriate height to its parent element as well. Otherwise you should look for another way to achieve your goal.

提交回复
热议问题