重叠两个 div 并“清除”他们的父div
我的 CSS-fu 让我失望了: 我想做的是将两个子 div (具有 可变 高度)定位为重叠。
使用:位置:绝对;顶部:0px; left: 0px;
是我知道的唯一方法,将父级设置为 position:relative
。
这样做的问题是,子 div 会根据 CSS 规范从布局中取出,将父 div 缩小到高度:0px,这样我就无法清除该 div 并在下面放置任何内容。
下面我令人惊叹的 ASCII 艺术详细说明了我想要的内容...有什么想法吗?
顺便说一句,我需要这些 div 完全重叠以实现平滑的 jQuery 淡入淡出,并且可能尝试一些新的 Webkit 转换,例如 Apple 的 cardflip 演示: https://developer.apple.com/library/archive/ Samplecode/CardFlip/Introduction/Intro.html
如果有另一种方法可以让它们在 CSS 中完全重叠,和/或如果有另一种方法可以通过两个子 div 获得类似卡片翻转的操作(使用 jQuery 或 Webkit/CSS)高度可变,我洗耳恭听!
|-------------------------------------------------|
| Parent div |
| |-------------------------------------------| |
| | | |
| | DIVS 1 & 2 (overlapped) | |
| | | |
| |-------------------------------------------| |
|-------------------------------------------------|
...more content below, after clearing the parent...
My CSS-fu is letting me down here:
What I'd like to do is position two child divs (with variable heights) to be overlapping.
Using: position: absolute; top: 0px; left: 0px;
is the only way I know how, with the parent set to position: relative
.
The problem with this is that the child divs are taken out of the layout as per the CSS spec, shrinking the parent div to height: 0px, so that I can't clear that div and put any content below.
My amazing ASCII art below details what I'm going for... any ideas?
As an aside, I need these divs to be overlapping exactly for smooth jQuery fades, and maybe trying out some of the new Webkit transforms, a la Apple's cardflip demo:
https://developer.apple.com/library/archive/samplecode/CardFlip/Introduction/Intro.html
If there's another way to get them overlapped exactly in CSS, and/or if there's another way to get cardflip-like action (using jQuery or Webkit/CSS) with two child divs of variable heights, I'm all ears!
|-------------------------------------------------|
| Parent div |
| |-------------------------------------------| |
| | | |
| | DIVS 1 & 2 (overlapped) | |
| | | |
| |-------------------------------------------| |
|-------------------------------------------------|
...more content below, after clearing the parent...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其中之一设置为
postition:absolute
怎么样?这样,一个子 div 仍将为父 div 提供高度,但另一个将从流程中取出。只是一个 jQuery 建议:
现在您将在两个
之间实现无缝淡入淡出
How about just setting one of them to
postition:absolute
? That way one child div will still give height to the parent div, but the other will be taken out of the flow.Just a jQuery suggestion:
And now you'll have seamless fades between the two
<div>
'sposition:relative
和负边距怎么样?我的头顶上浮现出:
What about
position: relative
and negative margins?Off the top of my head: