我有一個HTML代碼,這樣的寬度:如何設置一個div等於其兄弟IMG的寬度
<div class="card">
<div class="card-content">
<img src="somesource.png" width=480px height=320px>
<footer>
Some text here that makes the width of this footer greater than the width of sibling img tag.
</footer>
</div>
</div>
我想頁腳具有相同的寬度作爲其兄弟的IMG沒有影響圖像的寬度。圖像的寬度將根據所包含的圖像而有所不同,但我希望頁腳的寬度與圖像的寬度完全相同。 我曾嘗試以下:
.card {
display: inline-block;
}
.card-content {
display: flex;
flex-direction: column;
}
但它拓寬了IMG如果頁腳比圖像更廣泛。這不是我想要的。我希望頁腳的寬度取決於圖像的寬度,而不是相反。
請幫幫我。提前感謝您的建議。
非常感謝。它工作得很好。 –