【发布时间】:2020-07-17 22:57:36
【问题描述】:
当弹性框被放在float: left 旁边时会出现,它会占用剩余空间,并且不会环绕浮动。
这是如何以及为什么会发生的?任何其他display 可以做到这一点,还是 flexbox 独有的?
.float {
float: left;
padding: 10px;
background: rgba(0,255,0,.1)
}
.regular-div {
padding: 10px;
background: rgba(0,0,255,.1);
}
.flexbox {
display: flex;
padding: 10px;
background: rgba(0,255,255,.1);
}
.table {
display: table;
padding: 10px;
background: rgba(255, 255, 0, .1);
}
<b>Example one: Float with a div next to it</b>
<div>
<div class="float">
I am floating left.
</div>
<div class="regular-div">
I'm a regular div after the float.
<br>My content should wrap around the float.
<br>Look at it go!
<br>Wow!
</div>
</div>
<br><br>
<b>Example two: Float with a flexbox next to it</b>
<div>
<div class="float">
I am floating left.
</div>
<div class="flexbox">
I'm a flexbox. I do not wrap the div, and I occupy the remaining space to the right.<br>
Why does this happen?
Can any other "display" do this?
</div>
</div>
<br><br>
<b>Example three: Float with a table next to it</b>
<div>
<div class="float">
I am floating left.
</div>
<div class="table">
I am a table.<br>
I position myself like a flexbox<br>
But I shrink to fit.
</div>
</div>
【问题讨论】:
标签: html css flexbox css-float