問題是,圖像作爲一個整體不得不伸展以適應調整窗口的大小。如何使Flexbox項目適合其圖像尺寸?
大部分圖片都可以正常工作,但最後一張圖片的寬度不同,它只是調整大小。
它必須是絕對位置,因爲下面有一個網頁畫布。
我想我嘗試了一切,所有的flex-grow,flex-basis的東西。我不明白。
正如您在示例中看到的那樣,最後一張圖片應該與其他圖片在高度方向上吻合,但我無法將其合理化。
.container img {
width: 100%;
}
.container {
width: 40%;
background: #777;
}
.container2 {
width: 12.5%;
background: #777;
}
.myflex {
display: flex;
position: absolute;
}
<div class="myflex">
<div class="container">
<img src="https://placehold.it/512x512/000088/ffffff" />
</div>
<div class="container">
<img src="https://placehold.it/512x512/000088/ffffff" />
</div>
<div class="container">
<img src="https://placehold.it/512x512/000088/ffffff" />
</div>
<div class="container2">
<img style="" src="https://placehold.it/64x512/000088/ffffff" />
</div>
</div>
非常感謝您!你能解釋一下'.flex-item 4 {}'語法嗎?它在vscode中無效,但它起作用。我試着說'flex-item4 {}',但它不再工作了。它也只適用於基於Chrome的瀏覽器,不會在Firefox或Edge中顯示相同的正確結果。 – Blub