如何在 html/css 中使用 sprite 图像并使用 jQuery 切换更改
我尝试以这种方式使用它:
CSS
#sprite2 {
background: url(../images/csg_sprite.png) no-repeat top left;
}
.collapse_down{ background-position: 0 0; width: 16px; height: 16px; }
.collapse_up{ background-position: 0 -66px; width: 16px; height: 16px; }
HTML
<div id="sprite2"><span id="splink1" class="collapse_down">Defaults</span>
CHANGE by jQuery
$('#splink1').attr("class", 'collapse_up');
我面临的问题是图像应用于 div=sprite2而不是我想要的跨度。
如何修复文本左侧的问题以显示精灵,以及当我切换它时将图像更改为向上。
I am trying to use it this way:
CSS
#sprite2 {
background: url(../images/csg_sprite.png) no-repeat top left;
}
.collapse_down{ background-position: 0 0; width: 16px; height: 16px; }
.collapse_up{ background-position: 0 -66px; width: 16px; height: 16px; }
HTML
<div id="sprite2"><span id="splink1" class="collapse_down">Defaults</span>
CHANGE by jQuery
$('#splink1').attr("class", 'collapse_up');
The problem I face is that the image is applied for the div=sprite2 and not for the span I want for.
How to fix so on the left of the text to display the sprite, and when I toggle it, to change the image to up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当添加了包含背景图像的 id 或 class 时,才应用背景位置属性。
background position property applied only when id or class which includes background image added to it .
很简单:
将 CSS 从这样:更改
为这样:
Pretty simply:
Change your CSS from this:
to this: