【发布时间】:2016-06-13 03:41:49
【问题描述】:
我有一个大小为 1030px-510px 的大图像(图像精灵),其中包含两个小图像 (515px-515px)。
我想从精灵中获取两个小图像并为两个<img> 标签设置背景。我正在使用此代码:
.img-1, .img-2 {
width: 515px;
height: 515px;
background: url(http://i.stack.imgur.com/aozNS.png) no-repeat;
}
.img-1 {
background-position: 0px 0px;
}
.img-2 {
background-position: -515px 0px;
}
<div class="col-sm-6">
<img class="img-1">
</div>
<div class="col-sm-6">
<img class="img-2">
</div>
但是这两个图像比我的两个 div (class="col-sm-6") 大。那么,有什么方法可以将我的两个小图像放入我的两个 div 中?
我不想将我的两个 div 更改为更大的 (class="col-sm-7")。
【问题讨论】:
-
为什么使用
元素作为背景?这不是 s 的用途。