如果先前的同級設置爲寬度爲100%的float
,並且後面的同級設置爲display: flex
,後者會溢出父容器而不是換行到新行。如果之前的兄弟對象被浮動,則Flex容器溢出
與任何其他display
值,但flex
(或grid
)它包裝,因爲它應該,那爲什麼它不會當設置爲flex
.float-left {
float: left;
width: 100%;
}
.display-flex {
display: flex;
background: yellow;
}
/* Demo css */
.container {
max-width: 80%;
margin: auto;
background: white;
}
<div class="container">
<div class="float-left">I'm floating left, with a width of 100%.</div>
<div class="display-flex">'Floating left' takes up 100% of the space, but still i don't go onto a new line?</div>
</div>
你想達到什麼目的? – Phantom
嗯,有趣。如果你使它成爲'inline-flex',它會包裝。我想這可能是您找到的Flexbox錯誤,但由於所有瀏覽器都具有相同的行爲,因此可以通過設計。讓我們知道你想要完成什麼,我們將找到一個解決方法 – LGSon
Ubby,我編輯了你的問題,所以更清楚這與'.display-flex'_not_無關是一個彈性項目,它是關於它是一個彈性容器。 – LGSon