我有一个CSS sprite,其大小为32x32px的各种图标。使用CSS从sprite调整图像
现在我需要的是显示20x20px大小的图标之一。我尝试了一些东西,比如使用background-size:cover或者使用transform:scale(0.625)来设置大小为20px,但我的努力没有给出我想要的结果。
HTML我的测试:
32px icons:
<div class="sprite" style="background-position:0px 32px;"> </div>
<div class="sprite" style="background-position:64px 32px;"> </div>
<div class="sprite" style="background-position:32px 96px;"> </div>
<div class="sprite" style="background-position:0px 0px;"> </div>
<div class="sprite" style="background-position:32px 64px;"> </div>
<hr>
20px icons (attempts):
<div class="sprite" style="background-position:32px 64px; width:20px; height:20px;"> </div>
<div class="sprite" style="background-position:32px 64px; width:20px; height:20px; background-size:cover;"> </div>
<div class="sprite" style="background-position:32px 64px; width:20px; height:20px; transform:scale(0.625);"> </div>
CSS对我的测试:
.sprite {
background-image:url(http://buildnewgames.com/assets/article//dom-sprites/spritesheet.png);
width:32px;
height:32px;
}
请看看这个小提琴,看看我的尝试:
https://jsfiddle.net/dfqh0yrc/4/
的可能的复制[我怎么能扩展在CSS精灵的图像(http://stackoverflow.com/questions/2430206/how-can-i-scale- an-image-in-a-css-sprite) – Punit