调整父div的大小以匹配绝对定位的子div高度 [英] Resize parent div to match absolutly positioned child div height

查看:140
本文介绍了调整父div的大小以匹配绝对定位的子div高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSS问题:

我在容器中有一个绝对定位的div。容器不会调整到内容的高度。为什么?

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

推荐答案

您需要使用JavaScript。使用jQuery你可以做

You need to use JavaScript for this. With jQuery you can do

var parentHeight = $('#parent').height(),
    childHeight = $('#child').height();

if (parentHeight <= childHeight) {
    $('#parent').height(childHeight);
}

这篇关于调整父div的大小以匹配绝对定位的子div高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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