<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.father{
width: 500px;
height: 500px;
background-color: orange;
margin:0 auto;
position:relative;
}
.son{
width: 100px;
height: 100px;
background-color: #ccc;
position:absolute;
left:100px;
top:100px;
}
.box{
width: 1226px;
height: 460px;
position:relative;
}
.nav{
width: 300px;
height: 460px;
background-color: rgba(0,0,0,0.6);
position:absolute;
top:0;
left:0;
}
</style>
</head>
<body>
<!--
当对象作为子元素时, 做绝对定位, 若想在父级元素内部做绝对定位, 那么父级必须加上定位
常用于: 多个对象重叠在一起
-->
<div class='father'>
<div class='son'></div>
</div>
<div class='box'>
<img src="datu.jpg" alt="">
<div class='nav'></div>
</div>
</body>
</html>
多个div重叠一起必须在父元素内加绝对定位
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。