我有一个 CSS 问题:
我在容器中有一个绝对定位的 div。容器不会根据内容的高度调整大小。为什么?
最佳答案
您需要为此使用 JavaScript。使用 jQuery 你可以做到
var parentHeight = $('#parent').height(),
childHeight = $('#child').height();
if (parentHeight <= childHeight) {
$('#parent').height(childHeight);
}
在 http://jsfiddle.net/mkCU5/2/ 查看工作示例
关于javascript - 调整父 div 的大小以匹配绝对定位的子 div 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5359574/