![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b76e58105271c9a3afe734714cc37a1f.png#pic_center)
<!DOCTYPE html>
<html lang="en">
<head>
<title>绝对定位溢出隐藏</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
h2 {
color: gray;
}
.parent {
width: 100%;
height: 100px;
background-color: black;
position: relative;
overflow: hidden;
margin-bottom: 100px;
}
.parent1 {
width: 100%;
height: 100px;
background-color: black;
overflow: hidden;
}
.child {
position: absolute;
width: 90%;
height: 200px;
font-size: 2vw;
background-image: linear-gradient(#e66465, #9198e5);
}
</style>
<body>
<h3>需求: 设置绝对定位的同时让overflow:hidden生效</h3>
<h2>解决方法: 设置父盒子position:relative</h2>
<div class="parent">
<div class="child">父盒子设置相对定位</div>
</div>
<div class="parent1">
<div class="child">父盒子未设置相对定位</div>
</div>
</body>
</html>