html - 将一个块覆盖在另一个 CSS 上
问题描述
我需要像这样将 div 覆盖到 div img 灰色 div 应该覆盖右上角的黄色 div
我试过这样,但黄色没有进入我需要的位置
.grid {
display: grid;
/* grid-auto-rows: 100px;
grid-auto-columns: 100px; */
}
.item-1 {
grid-row: 1 / 2;
grid-column: 5 / 4;
}
.item-2 {
grid-row: 2 / 3;
grid-column: 2 / 4;
}
.item-1 img {
width: 200px;
height: 170px;
}
.item-2 img {
width: 368px;
height: 350px;
}
<div class="grid">
<div class="item-1">
<img src="img/square.png" alt="">
</div>
<div class="item-2">
<img src="img/Rectangle 24.png" alt="">
</div>
</div>
解决方案
你应该能够通过这样做来做到这一点。只需将您想要的元素放在您想要重叠的元素内,给它一个绝对位置,然后分配左/右值。
.box1 {
background: yellow;
position: relative;
width: 200px;
height: 200px;
margin: 100px;
}
.box2 {
background: gray;
position: absolute;
width: 200px;
height: 200px;
right: 120px;
top: 120px;
}
<div class="box1">
<div class="box2"></div>
</div>
推荐阅读
- spring-boot - Spring序列化的双数格式
- visual-studio - 升级到 Visual Studio 2019 16.7.1 后,程序挂起
- python - 在 vscode 中为 python 配置智能感知时需要帮助
- android - 存在实施时禁用中介网络 (Android Admob)
- gnuplot - 是否可以调整 gnuplot 方框图的高度?
- typescript - NodeJS FactoryGirl:错误:“代码”列中的空值违反非空约束
- python - Python多处理一个工人动态所有工人数据的接收者数量(1:n)
- docker - Jenkins 声明式管道调用方法阶段
- amazon-web-services - 如何查找特定区域和实例类型的 AMI ID?
- postgresql - 将 bytea 转换回 varchar