Auto height on parent container with Absolute/Fixed Children

后端 未结 8 2060
长情又很酷
长情又很酷 2020-11-28 10:29

Im trying to set an automatic height a div that contains 2 child elements, positioned fixed and absolutely respecitvely.

I want my parent container to have an auto h

相关标签:
8条回答
  • 2020-11-28 11:08

    If you don't want to use JavaScript, you could refer this answer https://stackoverflow.com/a/33788333/1272106.

    Short description: duplicate one element and set visibility to hide to expand the parent.

    0 讨论(0)
  • 2020-11-28 11:11

    http://jsfiddle.net/dPCky/32/ - A similar effect using float:left;

    http://jsfiddle.net/dPCky/40/ - An even closer result to your desired effect.

    If you're willing to change your html, then you could do what I have done above.

    I learned positioning from the following tutorials which I would highly recommend to anyone who wants to become a positioning pro in html/css:

    http://www.barelyfitz.com/screencast/html-training/css/positioning/

    I would generally avoid using javascript where possible when doing something that could potentially have a css or html level fix, if you're willing to adjust your html.

    0 讨论(0)
提交回复
热议问题