CSS-位置:绝对; -自动高度 [英] CSS - position: absolute; - auto height

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

问题描述

我在某些div上有问题

I am having a problem with some div's

外部div的高度为最小值,但内部div的高度均不同.由于内部div是绝对位置,因此它们不影响外部div的高度.有没有办法使这些内部div影响外部div的高度?

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?

我将这些div设置为position:absolute的原因是,它们都从容器div的顶部开始.

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

推荐答案

据我所知,绝对定位的子元素无法静态影响其高度,或者仅使用CSS不能相对定位父元素.要么

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:

  • 重新组织,以使子元素保留在文档流中
  • 在页面加载时使用JavaScript将父级的高度设置为最大子级的高度

此问题在淡入/淡出JavaScript幻灯片演示中很常见,从我看到的情况来看,要么1)需要定义父容器的高度,要么2)为每个容器动态设置父容器的高度幻灯片.

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-位置:绝对; -自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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