【发布时间】:2020-07-12 18:16:21
【问题描述】:
我的 img 生成随机大小的随机图像,有时高有时宽。如何使 img 永远不会大于或小于父容器?高 100% 高,宽 100% 宽。
.image-container{
width: 75rem;
height: 50rem;
}
/**this does not work**/
img{
max-width:100%;
max-height:100%;
}
【问题讨论】:
-
你试过 img{ width: 75rem;高度:50rem; }
-
改用
width:img{ width: 100%; height: 100%; }。 -
工作正常,肯定还有别的。