[英]Image height: auto doesn't work on chrome
I created a website with images that have a width of 160px
. 我创建了一个网站,其图像宽度为160px
。 To avoid a distortion I don't set the height (or I add height:auto;
). 为了避免失真,我没有设置高度(或者我添加height:auto;
)。 Now the image height should be automaticly set ( 90px
when the image is 16/9). 现在,图像高度应设定全自动( 90px
时,图像是16/9)。
But when I open it with Chrome the image height is set to the original image height ( 1080px
) while it still has a width of 160px
, therefore its very distorted 但是,当我使用Chrome打开它的图像高度设置为原始图像高度( 1080px
),而它仍然具有宽度160px
,因此它非常扭曲
Do you know why it doesnt work with chrome? 你知道为什么它不能用于chrome吗? (Neither on Mobile nor on Desktop) And how can I make it work. (无论是在手机上还是在桌面上)我怎样才能让它发挥作用。
One solution would be to se the height manually to 90px
, but I want to set the width to 90%
of the parent which makes the width different on different screens. 一种解决方案是手动将高度设置为90px
,但我想将宽度设置为父级的90%
,这使得不同屏幕上的宽度不同。 Therefore a set height doesn't make sense. 因此,设定高度没有意义。 But I also don't want to use JS 但我也不想使用JS
Distortion on chrome but not on firefox <div style="display:flex;"> <img src="https://i.imgur.com/hHzrRsf.jpg" style="width:160px;"> </div>
Try this: 尝试这个:
<div style="display:flex;"> <img src="https://i.imgur.com/hHzrRsf.jpg" style="width:160px;align-self: center;"> </div>
By default, align-self
is set to stretch
and remove the original height of your image. 默认情况下, align-self
设置为stretch
并删除图像的原始高度。
<div style="display:flex;"> <img src="https://i.imgur.com/hHzrRsf.jpg" style="width:160px; height:100%;"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.