css - [position相关]父元素fixed,子元素absolute,为什么父元素不能被子元素的内容撑开?
本文介绍了css - [position相关]父元素fixed,子元素absolute,为什么父元素不能被子元素的内容撑开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<style>
div{
box-sizing: border-box;
}
.container{
width: 100%;
position: fixed;
border:1px dashed green;
}
.content{
position: absolute;
width: 500px;
height: 500px;
border: 1px dashed red;
}
</style>
<div class="container">
<div class="content">
</div>
</div>
解决方案
.content
设置了position: absolute;
只是相对于于.container
绝对定位而已。设置了position: absolute
是不会占位置的!
这篇关于css - [position相关]父元素fixed,子元素absolute,为什么父元素不能被子元素的内容撑开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文