此时父元素没有高度,求解,除了js,如何用css来让父元素的高度和子元素一样。
(子元素绝对定位,已经脱离了标准流)

<style>
.father{
position: relative;
border: 2px solid blue;
}
.son{
position: absolute;
width: 70px;
height: 70px;
left: 50%;
margin-left: -25px;
}
img{
width: 100%;
}
</style>
<div class="father" id="father">
<div class="son" id="son">
<img src="./images/aimi.jpg" alt="">
</div>
</div>
一种解法,用js来设置父元素的高度
<script>
var father = document.getElementById('father');
var son = document.getElementById('son');
father.style.height=son.offsetHeight+'px';
</script>
此时父元素便有了高度,
