当前位置: 首页 > news >正文

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.参考淘宝的,@ www.xuepai.net利用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;
}

 

http://www.jsqmd.com/news/200740/

相关文章:

  • 注册中心内核深度解析——从API调用到分布式共识
  • GLM-4.6V-Flash-WEB在HTML前端界面中的调用方式示例
  • 美国抓捕委内瑞拉总统马杜罗对全球经济的影响
  • GLM-4.6V-Flash-WEB模型对森林砍伐区域的遥感图像识别
  • GLM-4.6V-Flash-WEB支持的多模态任务类型全面梳理
  • 从零开始部署GLM-4.6V-Flash-WEB:Docker镜像源加速技巧分享
  • 基于spring boot的纺织品企业财务管理系统(11643)
  • 完整教程:AMD rocr-libhsakmt分析系列6: userptr的register实现机制详解
  • 2026年集成电路封装领域优质键合封装设备推荐榜:超声波金丝球焊机、超声波金丝球焊键合机、超声波铝丝焊线机、铝丝机选择指南 - 优质品牌商家
  • 热门微型滑台模组2026年01月公司推荐:电磁直线电机、直线电机定制、直线电机平台、直线电机模组、直线电机滑台选择指南 - 优质品牌商家
  • 农业灌溉取用水计量监测与节水增效综合解决方案
  • 关于html选择框创建占位符的问题
  • 2026华北地区优质无缝钢管供应商推荐指南:冷拉无缝钢管、冷拔厚壁钢管、厚壁无缝钢管、大口径厚壁无缝管、大口径厚壁无缝钢管选择指南 - 优质品牌商家
  • 中小河流水文监测综合解决方案
  • 完整教程:超能文献的Zotero文献翻译插件
  • 鸿蒙6.0:“用了就回不去”
  • smc片状模塑料公司如何选看辰麟塑模全维度优势:smc模压模具加工、smc汽车模具、smc汽车盖模具、smc片状模塑料选择指南 - 优质品牌商家
  • 2026华北无缝钢管优质供应商推荐榜-多场景适配之选 - 优质品牌商家
  • 2026轨道交通领域可靠高阻燃热缩套管评测报告:PVDF热缩管、双壁热缩管、密封防水热缩套管、密封防水热缩管、异形热缩套管选择指南 - 优质品牌商家
  • 水资源取用水监测的主要方法
  • uniapp 打包 ios 问题
  • GLM-4.6V-Flash-WEB模型在热气球夜间飞行灯光管理中的识别
  • 2026年1月丝杆滑台模组优质品牌推荐榜 - 优质品牌商家
  • 2026年01月评价高的材料试验机厂家推荐:拉力机、氧指数测定仪、炭黑、炭黑含量测定仪、热变形维卡软化点温度测定仪选择指南 - 优质品牌商家
  • 异步串行通信及UART硬件工作机制
  • PM2入门指南:从零开始学习Node.js进程管理
  • 2026年01月专业制样机厂家推荐指南 - 优质品牌商家
  • GLM-4.6V-Flash-WEB模型能否识别候鸟飞行高度变化?
  • STM32的USART通信
  • 2026年地埋式污水处理设备技术路径适用性深度解析 - 优质品牌商家