图片宽高不固定 ,一样实现自适应,拉伸裁剪不变形,适应各大兼容性。

 


 下面咱们在网上找两张宽高不一样的照片:

          No.1                                              No.2

css+background实现 图片宽高自适应,拉伸裁剪不变形      css+background实现 图片宽高自适应,拉伸裁剪不变形

 

从上图看一个宽的一个窄的,很难做到自适应,无奈可恶的产品经理,只能自己想办法了

 请看下面图片,经在各大浏览器和手机端测试,是好用的                       


        

  咱们先来个对比:

 

    好用                                                不好用

css+background实现 图片宽高自适应,拉伸裁剪不变形css+background实现 图片宽高自适应,拉伸裁剪不变形

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

下面是调试好用的代码:直接放个div就OK啦。


 

 

<div style="
  width:500px;
  height:600px;
  border: 1px solid #000000;
  background: url(http://img.zcool.cn/community/01b34f58eee017a8012049efcfaf50.jpg@1280w_1l_2o_100sh.jpg) no-repeat;
  background-size:cover;
  background-position: center center;
">
</div>
<div style="
  width:500px;
  height:600px;
  border: 1px solid #000000;
  background: url(http://img17.3lian.com/d/file/201703/07/4ceeb6fc3d7956ac7731290a603e0a84.jpg) no-repeat;
  background-size:cover;
  background-position: center center;
">
</div>

 

相关文章:

  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-10-05
  • 2022-01-25
  • 2021-12-02
猜你喜欢
  • 2021-12-12
  • 2021-04-02
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
相关资源
相似解决方案