Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Html CSS:将div容器放在div容器中_Html_Css - Fatal编程技术网

Html CSS:将div容器放在div容器中

Html CSS:将div容器放在div容器中,html,css,Html,Css,我想在另一个div容器中设置一个div容器。信息容器应该可以放置在我想要的地方,例如:float:right;另外一个应该在里面 但是在我的例子中,它把容器放在它们之间,而不是里面 下面是我的HTML代码: <div class="info"> s <div class="info-header"> ss </div> </div> 提前谢谢 从第二个div css中删除绝对位置,然后尝试第二个div不应具有绝对位

我想在另一个div容器中设置一个div容器。信息容器应该可以放置在我想要的地方,例如:float:right;另外一个应该在里面

但是在我的例子中,它把容器放在它们之间,而不是里面

下面是我的HTML代码:

<div class="info">
    s
    <div class="info-header">
    ss
    </div>
</div>

提前谢谢

从第二个div css中删除绝对位置,然后尝试第二个div不应具有绝对位置。具有位置的元素:绝对;相对于最近定位的祖先定位,而不是相对于视口定位,如固定

但是,;如果绝对定位元素没有定位的祖先,它将使用文档体,并随着页面滚动而移动

如果要在第二个div上使用绝对定位,必须将第一个div设置为相对位置

检查codepen以获取示例:

我希望这样做:

身体{ 填充:20px; 背景色:20262e; } 部门信息{ 位置:绝对位置; 背景:ffdd57; 边界半径:3px; 填充:20px; 右:0;/*如果左注释更高*/ 显示:网格; 网格模板列:repeatauto-fit,minmax140px,1fr; 栅隙:10px; } div.info-header{ 职位:相对人; 背景:05ffb0; 边界半径:3px; 填充:20px; 字体大小:14px; } s 党卫军
div.info {
    position: absolute;
    background: yellow;
}
div.info-header {
    position: absolute;
    background: green;
}
div.info {
    position: relative;
    background: yellow;
    padding: 20px;
}
div.info-header {
    position: absolute;
    background: green;
}