CSS - postion:absolute; - 自动高度 [英] CSS - postion: absolute; - auto height

查看:680
本文介绍了CSS - postion:absolute; - 自动高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些div的问题









外部div有一个最小高度,但内部div都是变化的高度。因为内部div是绝对定位的,它们不影响外部div的高度。有没有办法让这些内部div影响外部div的高度?



我使用位置:绝对样式的这些div的原因是,他们都开始容器div的顶部。

解决方案

据我所知,绝对定位的子元素没有办法影响高度的静态或相对定位的父元素使用CSS。




  • 重新组织,以便子元素保留在文档流程中



  • 此问题在淡入/淡出时很常见 - 从我看过的任何1)父容器的高度需要定义或2)父容器的高度是动态为每个幻灯片设置。


    I am having a problem with some div's

    The outer div has a min-height, but the inner divs are all varying heights. Because the inner divs are absolute positioned, they do not affect the outer divs height. Is there a way to make these inner divs affect the height of the outer div?

    The reason I am styling these divs with position:absolute is so that they all start at the top of the container div.

    解决方案

    As far as I know, there's no way for absolutely positioned child elements to affect the height of their statically, or relatively positioned parent elements using only CSS. Either:

    • Reorganize so that the child elements remain in the document flow
    • Use JavaScript on load of the page to set the height of the parent to the height of the largest child

    This issue is common in fade-in/fade-out JavaScript slideshows, and from what I've seen either 1) the height of the parent container needs to be defined or 2) the parent container's height is set dynamically for each slide.

    这篇关于CSS - postion:absolute; - 自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆