Resize image proportionally with CSS?

2018-12-31 21:20发布

Is there a way to resize (scale down) images proportionally using ONLY CSS?

I'm doing the JavaScript way, but just trying to see if this is possible with CSS.

18条回答
何处买醉
2楼-- · 2018-12-31 21:42

Control size and maintain proportion :

#your-img {
    height: auto; 
    width: auto; 
    max-width: 300px; 
    max-height: 300px;
}
查看更多
明月照影归
3楼-- · 2018-12-31 21:45

To resize the image proportionally using CSS:

img.resize {
    width:540px; /* you can use % */
    height: auto;
}
查看更多
伤终究还是伤i
4楼-- · 2018-12-31 21:45
img {
    max-width:100%;
}

div {
    width:100px;
}

with this snippet you can do it in a more efficient way

查看更多
弹指情弦暗扣
5楼-- · 2018-12-31 21:46

The css properties max-width and max-height work great, but aren't supported by IE6 and I believe IE7. You would want to use this over height / width so you don't accidentally scale an image up. You would just want to limit the maximum height/width proportionately.

查看更多
看淡一切
6楼-- · 2018-12-31 21:47

You always need something like this

html
{
    width: 100%;
    height: 100%;
}

at the top of your css file

查看更多
无与为乐者.
7楼-- · 2018-12-31 21:51

Try

transform: scale(0.5, 0.5);
-ms-transform: scale(0.5, 0.5);
-webkit-transform: scale(0.5, 0.5);
查看更多
登录 后发表回答