我有一个简单的div标记:
<div class="gallery__card">
<img class="gallery__card__img" src="1.jpg">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
</div>
但我希望gallery__card
和gallery__card__img
一样宽,这样图片下面的文本就不会占满整个页面宽度。
有没有一种方法可以在不使用JS或固定宽度的情况下实现这一点?
jsfiddle: http://jsfiddle.net/6h19oa1q/
.gallery__car
的宽度设置为特定值,然后将.gallery__card__img
的宽度设置为100%,高度设置为自适应。 - Mattia Nocerinoheight: auto
是隐含的,同时 OP 希望避免固定宽度,但这当然也是一个选项。 - justinw