en~~~~~~
定位的元素子元素撑满父元素
新发现,发现一种写法,有两个div,是父子关系,
父元素设置了宽高,以及绝对定位,
子元素如何撑满父元素,不用宽高的情况下,
就是让子元素,也绝对定位,top/left/right/bottom都设置为0就好了,
发现新大陆,哦吼吼~~
<style>
.box {
width: 500px;
height: 500px;
background-color: #f00;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.mask{
position: absolute;
left:0;
top: 0;
right: 0;
bottom: 0;
background-color: #000;
opacity: .5;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div class="box">
<div class="mask"></div>
</div>