CSS强制图像调整大小并保持纵横比

本文翻译自:CSS force image resize and keep aspect ratio

I am working with images, and I ran across a problem with aspect ratios. 我正在使用图像,我遇到了纵横比问题。

<img src="big_image.jpg" width="900" height="600" alt="" />

As you can see, height and width are already specified. 如您所见,已指定heightwidth I added CSS rule for images: 我为图片添加了CSS规则:

img {
  max-width:500px;
}

But for big_image.jpg , I receive width=500 and height=600 . 但是对于big_image.jpg ,我收到width=500height=600 How I can set images to be re-sized, while keeping their aspect ratios. 我如何设置图像以重新调整大小,同时保持其纵横比。


#1楼

参考:https://stackoom.com/question/sVdv/CSS强制图像调整大小并保持纵横比


#2楼

Remove the "height" property. 删除“高度”属性。

<img src="big_image.jpg" width="900" alt=""/>

By specifying both you are changing the aspect ratio of the image. 通过指定两者,您正在更改图像的纵横比。 Just setting one will resize but preserve the aspect ratio. 只需设置一个将调整大小但保留纵横比。

Optionally, to restrict oversizings: (可选)限制夸大:

<img src="big
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值