.zoomImage{
width:100%;
height:0;
padding-bottom: 100%;
overflow:hidden;
background-position: center center;
background-repeat: no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
background-size:cover;
}
这里的原理是与背景图片方式实现
做站经常遇到,前台一些图片与实际展示的尺寸有出入,所以需要重新定义一下图片的大小,我用这方法解决的。
来说说原理吧。
<h2 style="box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: " microsoft="" yahei",="" "sf="" pro="" display",="" roboto,="" noto,="" arial,="" "pingfang="" sc",="" sans-serif;="" font-size:="" 24px;="" color:="" rgb(79,="" 79,="" 79);="" line-height:="" 32px;="" overflow-wrap:="" break-word;="" font-variant-ligatures:="" common-ligatures;="" white-space:="" normal;="" background-color:="" rgb(255,="" 255,="" 255);"="">原理剖析
width:100%; height:0; padding-bottom: 100%; overflow:hidden;
<h2 style="box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: " microsoft="" yahei",="" "sf="" pro="" display",="" roboto,="" noto,="" arial,="" "pingfang="" sc",="" sans-serif;="" font-size:="" 24px;="" color:="" rgb(79,="" 79,="" 79);="" line-height:="" 32px;="" overflow-wrap:="" break-word;="" font-variant-ligatures:="" common-ligatures;="" white-space:="" normal;="" background-color:="" rgb(255,="" 255,="" 255);"="">样式中的上面四句主要目的是为了让这个div以1:1的大小呈现,
<p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: " microsoft="" yahei",="" "sf="" pro="" display",="" roboto,="" noto,="" arial,="" "pingfang="" sc",="" sans-serif;="" font-size:="" 18px;="" color:="" rgb(77,="" 77,="" 77);="" line-height:="" 26px;="" overflow-wrap:="" break-word;="" font-variant-ligatures:="" common-ligatures;="" white-space:="" normal;="" background-color:="" rgb(255,="" 255,="" 255);"="">虽然height:0;高度为0,但是它的padding值为100%
这是因为在padding为百分比的时候,是根据他父层的宽度来进行计算的。
在一点MDN关于padding的文档 也有说到,有兴趣的同学可以看看。
background-position: center center; background-repeat: no-repeat; -webkit-background-size:cover; -moz-background-size:cover; background-size:cover;
<p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: " microsoft="" yahei",="" "sf="" pro="" display",="" roboto,="" noto,="" arial,="" "pingfang="" sc",="" sans-serif;="" font-size:="" 18px;="" color:="" rgb(77,="" 77,="" 77);="" line-height:="" 26px;="" overflow-wrap:="" break-word;="" font-variant-ligatures:="" common-ligatures;="" white-space:="" normal;="" background-color:="" rgb(255,="" 255,="" 255);"="">后面5句就是利用了css3中的 background-size:cover 的特性,把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。

Thomas2 年前
发表在:SQL Server2008报错:值不能为空[S35]
Thomas2 年前
发表在:解决Composer Installing dependencies from lock file你这都看不清了
1114 年前
发表在:Cetnos7 新手安装ZABBIX4.0.5详解教程有人嘛
Tyreunorm2020-08-27 22:51
发表在:php5.6 连接SQL SERVER<a href=https://mega...
耗子2020-04-08 15:02
发表在:写给正在创业的自己看到了,想写点。可能我开过这网站了,以后...
Thomas2019-11-19 19:57
发表在:twcms您的IP地址已改变,为了安全考虑,请重新登录这个好
酷喵2016-08-03 15:22
发表在:我家侄女成长记前排支持啦!
五爷2015-12-01 03:26
发表在:关于centos中的相关查看命令@admin:呵呵
admin2015-12-01 01:49
发表在:关于centos中的相关查看命令非常不错