gpt4 book ai didi

html - 100%高度体,绝对 child 也要100%

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:56 24 4
gpt4 key购买 nike

我正在尝试制作一个绝对定位的元素以占据 body 的 100% 高度, 其中body设置为获取 100% 的内容,可能会超过 window高度。但是,我似乎无法确定它。

CSS:

html
{
height: 100%;
}

body
{
min-height: 100%;
}

#push
{
padding-top: <to exceed window height>;
}

#absolute
{
position: absolute;

left: 0px;
top: 0px;

width: 100%; /* to take full width of body */

height: 100%; /* to take full height of body */
}

HTML(假设这是 <body> 中的所有内容):

<div id="push"></div>
<div id="absolution"></div>

fiddle :http://jsfiddle.net/psycketom/DbV4R/

我试过制作#absolute body 的第一个 child ,最后一个 child (假设 DOM 尚未计算 body 开始处的高度)。另外,尝试删除它的 height属性(property)交换top: 0; bottom: 0; - 运气不好。

嗯,我想这是因为 absolute文档流中取出元素,但是,难道没有办法绕过它吗?

我的实际示例是我想要一个绝对定位的背景附件元素,其中包含许多绝对定位的元素。该元素将具有 overflow: hidden不做任何滚动条。

除了 javascript 和定义的高度,我在这里有什么选择?

更新:

如果你检查 fiddle ,你会注意到 #absolution高度为 536px,body 为 600。

我要,#absolution , 也需要 600px - body 的全高.

最佳答案

让 body 位置相对?删除 body 的原生边距/填充以去除所有红色 ( http://jsfiddle.net/DbV4R/6/ )

http://jsfiddle.net/DbV4R/5

body {
position: relative;
}

关于html - 100%高度体,绝对 child 也要100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com