html布局,防止图片变形的两个方法

首先图片不能定高,这是肯定的

1.父盒子包裹,图片高auto

	<div>
      <img src="" alt="">
    </div>	

css

div{
  width: 1rem;
  height: 1rem;
  overflow: hidden;
  img{
    width: 100%;
    height: auto;
  }
}

2.背景图取图片中间内容

<div
  :style="{background:'url('+item+') no-repeat center center/cover'}">
</div>

css

div{
	  width: 1rem;
	  height: 1rem;
}

猜你喜欢

转载自blog.csdn.net/weixin_45389051/article/details/112617944