我有一个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如果页脚比图像更广泛。这不是我想要的。我希望页脚的宽度取决于图像的宽度,而不是相反。
请帮帮我。提前感谢您的建议。
非常感谢。它工作得很好。 –