问题描述
我想获得一个图像(动态放置,没有对尺寸的限制)与其父div一样宽,但只要该宽度不大于其自己的宽度在100%。我试过这个,没有效果:
I’m trying to get an image (dynamically placed, with no restrictions on dimensions) to be as wide as its parent div, but only as long as that width isn’t wider than its own width at 100%. I’ve tried this, to no avail:
img {
width: 100%;
height: auto;
max-width: 100%;
}
这些图片中的许多都比它们的父div宽,这就是为什么我'喜欢他们相应地调整大小,但是当一个小图像在那里弹出,并扩大超出其正常的维度,它真的看起来可怕。有没有办法这样做?
Many of these images are way wider than their parent div, which is why I’d like them to resize accordingly, but when a small image pops in there and gets scaled up beyond its normal dimensions, it really looks terrible. Is there any way of doing this?
推荐答案
只需指定 max-width:100%
单独,应该这样做。
Just specify max-width: 100%
alone, that should do it.
这篇关于将图片宽度设为父div的100%,但不得大于其自身的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!