3

例如,我有一个 3 个不同的图像作为带有悬停的精灵。

例如精灵

<div class="sprite normal"></div>

我不要这种类型!

/* small */
    .small{ width:20px; height:20px; }
    .small .sprite{ background:url(sprite.png) 0 0 no-repeat; }
    .small .sprite:hover { background:url(sprite.png) 20px 0 no-repeat; }
/* normal*/
    .normal{ width:50px; height:50px; }
    .normal .sprite{ background:url(sprite.png) 0 0 no-repeat; }
    .normal .sprite:hover { background:url(sprite.png) 50px 0 no-repeat; }
/* big */
    .big{ width:100px; height:100px; }
    .big .sprite{ background:url(sprite.png) 0 0 no-repeat; }
    .big .sprite:hover { background:url(sprite.png) 100px 0 no-repeat; }

有没有捷径?谢谢你..

4

2 回答 2

1
.sprite{ background:url(sprite.png) 0 0 no-repeat; }

/* small */
    .small{ width:20px; height:20px; }
    .small .sprite:hover { background:url(sprite.png) 20px 0 no-repeat; }

/* normal*/
    .normal{ width:50px; height:50px; }
    .normal .sprite:hover { background:url(sprite.png) 50px 0 no-repeat; }

/* big */
    .big{ width:100px; height:100px; }
    .big .sprite:hover { background:url(sprite.png) 100px 0 no-repeat; }
于 2013-09-27T09:49:19.157 回答
0
.sprite { background: url('sprite.png') 0 0 no-repeat; }

.small { width: 20px; height: 20px; }
.small:hover { background-position: 20px 0; }

.normal { width: 50px; height: 50px; }
.normal:hover { backgorund-position: 50px 0; }

.big { width: 100px; height: 100px; }
.big:hover { background-position: 100px 0 }

这些绝对都是必需的样式,你不会用更少的规则来实现你的目标。

于 2013-09-27T09:55:54.293 回答