Auto height on parent container with Absolute/Fixed Children

后端 未结 8 2062
长情又很酷
长情又很酷 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 10:48

    Related to @Blowsie's answer:

    /**
     * Sets the height of a container to its maximum height of its children. This
     * method is required in case
     * 
     * @param selector jQuery selector
     */
    function setHeightByChildrenHeight(selector)
    {
        $(selector).each(function()
        {
            var height = 0;
    
            $(this).children("*").each(function()
            {
                height = Math.max(height, $(this).height());
            });
    
            $(this).height(height);
        });
    };
    

提交回复
热议问题