跳转至内容
上海创厦网络科技
IT服务专家
上海创厦网络科技上海创厦网络科技
  • 首页
  • 网站建设
  • IT服务
  • 平面设计
  • 网络工程
  • 首页
  • 网站建设
  • IT服务
  • 平面设计
  • 网络工程

html css3不拉伸图片显示效果

您在这里:
  1. 首页
  2. HTML
  3. html …

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

html:

1
2
3

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

  

     
  

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是正方形。
淘宝的是这样的:

到此这篇关于html css3不拉伸图片显示效果的文章就介绍到这了,更多相关html css3不拉伸图片 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

Category: HTMLstartupplaza2022年5月30日评论

作者: startupplaza

文章导航

历史的文章历史的文章:前端html换肤功能的实现代码未来的文章未来的文章:html+css实现赛博朋克风格按钮

Related Posts

HTML基本标签及结构详解
2022年5月30日
html 指定页面字符集的两种方法
2022年5月30日
当div设置contentEditable=true时,重置其内容后无法光标定位
2022年5月30日
HTML用户注册页面设置源码
2022年5月30日
详解HTML元素的height、offsetHeight、clientHeight、scrollTop等梳理
2022年5月30日
利用div+css3实现一个背景渐变的button按钮的示例代码
2022年5月30日

技术探讨

  • 使用HTML5捕捉音频与视频信息概述及实例
  • HTML5 Canvas实现玫瑰曲线和心形图案的代码实例
  • 详解HTML5中的