我想创建一个精灵,其中有几个图像将用作背景。其中一些将与norepeat一起使用,一些将会有repeat-x。从精灵重复背景
设置此类样式的最佳方式是什么?
到目前为止,我已经试过,但它不能正常工作:
CSS
.sprites {
background-color: transparent;
background-image: url(img/sprites.png);
background-repeat: no-repeat;
}
.bg {
width: 1px;
height: 25px;
background-position: 0 0;
background-repeat: repeat-x;
}
HTML
<div class="sprites bg">
</div>
这甚至可能吗?
使用此方法的唯一警告是容器必须具有明确的高度才能隐藏背景图像的其余部分。 – Bojangles 2012-07-23 21:12:43
是的,这是一般使用精灵的警告。 – Andrew 2012-07-23 21:17:02