本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
html css3不拉伸图片显示效果
无间道 · 346浏览 · 发布于2021-06-22 +关注

本文主要介绍了html css3不拉伸图片显示效果,类似淘宝,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

1.利用transform属性不拉伸显示图片,(路径问题需要按需求修改);

html:

1

2

3

<div id="surface-div1">

<img :src="pic1" class="surface-img">

</div>

CSS:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

#surface-div1{

    position: relative;

    width: 372px;

    height: 175px;

    float: left;

    margin-top: -34px;

    margin-left: 122px;

    cursor: pointer;

    background: url(../../../static/img/addheadpic.jpg)center center no-repeat;

    text-align: center;

    border: 1px solid #CCCCCC;

    border-radius:6px;

    overflow: hidden;

}

#surface-div1 img{

    position: absolute;

    width: 100%;

    top: 50%;

    left: 0;

    transform: translateY(-50%) scale(1);

    border:none;

    border-radius: 6px;display:table-cell

}

这里写图片描述
这里写图片描述

最终效果如上图的左边。

2.参考淘宝的,利用display:table-cell和文字大小控制居中

html:

1

2

3

4

5

<div id="surface-div">

  <div class="sur-div">

     <img :src="pic" class="surface-img">

  </div>

</div>

css:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

#surface-div{

    position: relative;

    width: 372px;

    height: 372px;

    float: left;

    margin-top: -34px;

    margin-left: 122px;

    cursor: pointer;

    background: url(../../../static/img/addheadpic.jpg)center center no-repeat;

    text-align: center;

    border: 1px solid #CCCCCC;

    border-radius:6px;

    overflow: hidden;

}

.sur-div{

    display: table-cell;

    text-align: center;

    vertical-align: middle;

    font-size: 12px;

    width: 372px;

    height: 372px;

    overflow: hidden;

}

#surface-div img{  

    max-height: 100%;

    max-width: 100%;

    vertical-align: middle;

    border: 0;

}

这里写图片描述

效果如上图中的左边部分,重点是需要外面的div是正方形。
淘宝的是这样的:

这里写图片描述


相关推荐

RN开发环境的npm私库本地debug调试

manongba · 698浏览 · 2019-05-09 17:03:46
你不知道的浏览器渲染原理

追忆似水年华 · 1373浏览 · 2019-05-09 22:47:56
基于iview的router常用控制方式

追忆似水年华 · 999浏览 · 2019-06-03 10:39:21
编程小知识之 JavaScript 文件读取

manongba · 717浏览 · 2019-06-10 09:16:16
10个省时间的 PyCharm 技巧 赶快收藏!

· 703浏览 · 2019-06-10 09:32:01
加载中

0评论

评论
各位好,我是无间道,欢迎互助粉丝!
分类专栏
小鸟云服务器
扫码进入手机网页