利用 padding 来实现和利用css的伪类 after 或者before 来撑开css
width 百分之几 padding 百分之几 同样的宽度orm
具体代码以下blog
.product-image { position: relative; display: inline-block; width: 100%; overflow: hidden; } .product-image:before { display: block; content: ' '; padding-bottom: 100%; width: 1PX; } .product-image img { position: absolute; top: 50%; left: 0; width: 100%; transform: translateY(-50%); }