.responsive-img {
max-width: 100%;
height: auto; /* 保持比例 */
}
適用於 <img>、<video>、<canvas> 等置換元素。
.thumb {
max-width: 50px;
max-height: 50px;
width: auto; height: auto;
}
* html .thumb { /* IE6-7 only */
width: expression(this.width > 50 && this.width > this.height ? '50px' : 'auto');
height: expression(this.height > 50 ? '50px' : 'auto');
}
缺點:Expression 會頻繁重算、阻塞渲染、安全風險,微軟已棄用。
img { max-width: 100%; height: auto; }。object-fit: cover + 固定容器尺寸。