我玩花车,然后我注意到固定位置不会出现“float collapse bug”。这是 example .
所以我有两个 div:
<body
<div class="static">
<img>
<p>text text text</p>
</div>
<div class="fixed">
<img>
<p>text text text</p>
</div>
</body>
第一个是静态位置,第二个是固定位置:
.fixed, .static{
outline: 1px solid black;
width: 150px;
}
.fixed{
position: fixed;
left: 200px;
top: 200px;
}
img{
float: right;
background-color: green;
width: 100px;
height: 100px;
}
结果:
那么为什么第二个 fixed-div 不需要像 .clearfix
这样的东西来修复 float 折叠?
最佳答案
因为 position: fixed;
创建了 Block formatting context .
也试试下面的样式,它们在您的 div
中有类似的效果。
float
position
absolute
和fixed
display
-inline-blocks
、table
、table-cells
溢出
-隐藏
,自动
关于html - 为什么 float collapse 不会出现 fixed position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32032938/