答案 0 :(得分:2)
.sprite {
background-image: url("pathto/facebook_signin.png");
background-position: 0 0;
}
.sprite:hover {
background-position: 0 16px /*or whatever the y position of the 2nd button is*/
}
.sprite:active {
background-position: 0 32px /*or whatever the y position of the 3rd button is*/
}
答案 1 :(得分:1)
这样的事情应该有效:
a.fb {
display: block;
background: ("/path/to/sprite.png") 0 0 no-repeat; /* start with normal state */
width: 150px;
height: 18px;
text-indent: -9999px; /* for image replacement */
}
a.fb:hover,
a.fb:focus {
/* hover and focus state */
background-position: 0 -20px;
}
a.fb:active {
/* click state */
background-position: 0 -40px;
}
答案 2 :(得分:1)
如果您使用的是mac,则可以使用一些工具自动编写CSS文件。这些工具以有效的方式命令您的精灵,并为您编写CSS文件。您不需要与排序和计算像素坐标等进行斗争 建议Sprite Master。
答案 3 :(得分:0)
你的CSS究竟有什么用? Spriting涉及在悬停(或其他状态)下更改图像的背景位置。
所以它真的只是
#element {
background-position-y: 10px;
}
#element:hover {
background-position-y: 0px;
}
查看您的CSS会很有帮助。