【发布时间】:2017-02-28 14:11:26
【问题描述】:
我有一个正在使用的精灵,我想重用精灵中的一个图像,但大小只有一半,所以我想如果我只使用background-size:50%;,它会将背景大小调整 50%,但它由于某种原因,尺寸似乎缩小了四分之一:
.test {
background: url(https://i.stack.imgur.com/KaIav.png) left top no-repeat;
width: 112px;
height: 112px;
border: 1px solid red;
}
.test.half-size {
width: 56px;
height: 56px;
background-size: 50%;
}
<div class="test"></div>
<div class="test half-size"></div>
现在我可以通过将背景大小设置为 113% 来解决此问题:
.test {
background: url(https://i.stack.imgur.com/KaIav.png) left top no-repeat;
width: 112px;
height: 112px;
border: 1px solid red;
}
.test.half-size {
width: 56px;
height: 56px;
background-size: 113%;
}
<div class="test"></div>
<div class="test half-size"></div>
但是为什么图片小于原图时background-size大于100%?
在确定如何调整精灵大小时,我可以应用一组计算吗?
【问题讨论】:
标签: css background-size