![](/img/trans.png)
[英]Constrain and image max-width to parent container and re-scal height doesn't work in IE11
[英]max-width image doesn't expand the parent container
我將圖像縮略圖浮動到左側。 代碼如下:
<div id="imgContainer">
<div>
<a href="#" class="item"><img src="image.png" /></a>
</div>
</div>
這是css:
#imgContainer div {
width: 23%;
float: left;
padding: 1%;
position: relative;
}
#imgContainer img {
position: absolute;
top: 0;
left: 0;
width: 100%;
max-width: 290px;
}
問題是:它只能通過寬度將圖像拉伸到290px。 它似乎不會影響身高。 這導致真正拉伸的縮略圖。 我需要它們最大寬度為290px,高度應相應縮放。
任何未指定的維度都應自動縮放,但您的圖像可能是繼承其他方面的樣式。 要恢復自動縮放高度,您應為#imgContainer img
指定以下屬性:
height: auto;
加:
#imgContainer img { height: 100% }
要么
#imgContainer img { height: auto }
應該夠了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.