Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 垂直堆叠固定div内的div_Css_Layout_Positioning - Fatal编程技术网

Css 垂直堆叠固定div内的div

Css 垂直堆叠固定div内的div,css,layout,positioning,Css,Layout,Positioning,我有一个垂直的父容器div,具有固定的位置和像素高度。我的子div与父div的宽度相同。如何将这些子div堆叠在固定父级中?我无法通过。请提供帮助。如果要静态执行,只需设置每个子div的top属性即可 所以如果那些小div的高度是50px #child1{ position:relative; top:50px; } #child2{ position:relative; top:100px; } 依此类推它们应该已经堆叠起来了。你能详细说明你的问题吗 HTML <div id="c

我有一个垂直的父容器div,具有固定的位置和像素高度。我的子div与父div的宽度相同。如何将这些子div堆叠在固定父级中?我无法通过。请提供帮助。

如果要静态执行,只需设置每个子div的top属性即可

所以如果那些小div的高度是50px

#child1{
position:relative;
top:50px;
}
#child2{
position:relative;  
top:100px;
}

依此类推

它们应该已经堆叠起来了。你能详细说明你的问题吗

HTML

<div id="container">
    <div class="stack one"></div>
    <div class="stack two"></div>
    <div class="stack three"></div>
</div>

已更新-

阅读您的回复后,我现在更新了CSS-

CSS

#container {
    width: 250px;
}

.stack {
    width: 250px; height: 100px;
}

.one { background: red; }
.two { background: green; }
.three { background: orange; }
#container {
    position: relative;
    width: 250px; height: 300px;
}

.stack {
    position: absolute;
    width: 250px; height: 100px;
}

.one { background: red; bottom: 0; }
.two { background: green; bottom: 100px; }
.three { background: orange; bottom: 200px; }

谢谢大家的回复。我的问题是我的容器有一个固定的像素高度。它不是动态调整大小。高度是固定的。我想让我的孩子像你把盘子放在桶里一样叠起来。通常情况下,孩子们都会站在最上面。我想让我的孩子沉到水底。