自动设置绝对子级的父div的高度
I've got a situation, where i have a few divs with absolute position (for 3d flipping effect ). As a result, parent div's height is very small and absolute content overflows on top of lower content. Can't really set a fixed height for responsive reasons.
我有一种情况,我有几个具有绝对位置的div(用于3D翻转效果)。因此,父div的高度非常小,绝对内容在较低内容之上溢出。由于反应原因,无法真正设置固定高度。
I'm planning to give children divs relative position, and then gather height with a help of jquery and set the height based on it. But there really is a lot of elements and vars for responsive. Is there any other, more elegant way to make children fit the parent?
我打算给孩子div相对位置,然后在jquery的帮助下收集高度并根据它设置高度。但是真的有很多元素和vars用于响应。有没有其他更优雅的方式让孩子适合父母?
http://jsfiddle.net/xyjrLa2p/
html
<div class="parent">
<div class="title">Title</div>
<div class="absolute">
<p>Absolute</p>
<p>Absolute</p>
<p>Absolute</p>
</div>
<div class="clearboth"></div>
</div>
css
.parent {
position:relative;
background-color:yellow;
}
.absolute {
position:absolute;
}
.absolute p {
padding:5px;
}
.clearboth {
clear:both;
}
2 个解决方案
#1
0
If you don't mind .absolute
posistion, try to make it relative
:
如果你不介意.absolute posistion,试着让它相对:
.absolute {
position:relative;
}
Working example -- http://jsfiddle.net/xyjrLa2p/3/
工作示例 - http://jsfiddle.net/xyjrLa2p/3/
更多相关文章
- 保持子div的宽高比与父级的高度和宽度变化
- 浮动到页面底部的可变高度页脚的CSS(不是视口)
- 100%高度分区内显示:表格单元分区
- JQuery基于元素的高度添加类
- IFrame中的Div没有达到给定的高度
- Chrome 50更改隐式表格单元格高度行为
- 两个堆叠DIV的顶部DIV如何影响另一个DIV的高度
- CSS:浮动时忽略div高度
- DiggBar如何基于不在其域上的内容动态调整其iframe的高度?