html - css中重叠元素而不使用网格
问题描述
如何在不使用网格的情况下在 CSS 中创建这种效果(参见片段中的图像)。我在想我是否可以使用定位或其他方式达到相同的效果。提前致谢!
<html>
<body>
<img src="https://i.stack.imgur.com/lDNov.png" style="width:100%">
</body>
</html>
解决方案
.parent {
width: 200px;
height: 200px;
border: 1px solid green;
position: relative;
}
.child {
position: absolute;
top: -10px;
left: -10px;
width: 100%;
height: 100%;
}
img {
width: 100%;
height: 100%;
}
<div class="parent">
<div class="child">
<img src="https://blog.prezi.com/wp-content/uploads/2019/03/joshua-earle-157231-unsplash-1024x683.jpg" />
</div>
</div>
推荐阅读
- gitlab - 从 gitlab 获取大于 100 的项目用于 sourcegraph projectQuery
- docker - 无法在 dockerfile 中安装 iputils 和 net-tools
- javascript - 如何在javascript中显示选定的元素
- flutter - Flutter - 从模拟器中完全卸载应用程序
- neo4j - 密码查询:根据其他属性关系的聚合设置关系上的属性
- c# - AutoUpdater.NET 不更新也不删除旧程序
- python - 从泡菜文件上传图表时出现问题
- php - 在 php 应用程序中存储 AES 加密密钥的最佳方法是什么?
- openoffice-calc - 将单元格中的数据拆分为新列 Openoffice Calc
- wpf - visual studio 2019 不显示添加新项目报告 rdlc