CSS 精灵和突出显示 - 可以应用“悬停”一次拥有多个物品的属性?
我有两个精灵图像。一张图像包含圆形按钮的主体以及其他状态(悬停、单击等),而另一张图像包含图像的最左侧曲线。
我正在使用这些按钮,因此我的网页上不必有多个按钮图像,这些按钮可以缩放到任何大小。
<div id="search_tips"><span>Search Tips</span></div>
和 CSS
#advanced_search_button, #search_tips{
background: url("graphics/doc_button_left.png") no-repeat scroll 0 0 transparent !important;
color:#666666 !important;
display:block !important;
float: right !important;
padding-left: 5px;
padding-right: 6px;
padding-top: 0px;
margin-right: 16px;
height: 22px;
overflow: hidden !important;
}
#advanced_search_button span, #search_tips span{
background: url("graphics/doc_button.png") no-repeat scroll 100% 0 transparent !important;
padding: 2px 9px 5px 0 !important;
line-height: 19px;
display:block !important;
float: left;
}
#search_tips:hover, #advanced_search_button:hover {
background-position: 0 -22px !important;
}
#search_tips span:hover, #advanced_search_button span:hover{
background-position: 100% -22px !important;
}
当我将鼠标悬停在包含 , (图标的大部分)的 div 部分上时,我的精灵的两个部分都应用了“悬停”样式。但是,如果我将鼠标悬停在“之前的图像部分上,我只会看到图像的一部分应用了“悬停”样式。
我想要做的是激活“悬停”样式每当父div应用它的悬停样式时,
有什么建议
吗?
I have a two sprite images. One image contains the body of a rounded button as well as other states (hover, clicked, ect) while the other contains the left most curve of the image.
I am using these so I don't have to have multiple button images on my webpage, these buttons are can be scaled to any size.
<div id="search_tips"><span>Search Tips</span></div>
and CSS
#advanced_search_button, #search_tips{
background: url("graphics/doc_button_left.png") no-repeat scroll 0 0 transparent !important;
color:#666666 !important;
display:block !important;
float: right !important;
padding-left: 5px;
padding-right: 6px;
padding-top: 0px;
margin-right: 16px;
height: 22px;
overflow: hidden !important;
}
#advanced_search_button span, #search_tips span{
background: url("graphics/doc_button.png") no-repeat scroll 100% 0 transparent !important;
padding: 2px 9px 5px 0 !important;
line-height: 19px;
display:block !important;
float: left;
}
#search_tips:hover, #advanced_search_button:hover {
background-position: 0 -22px !important;
}
#search_tips span:hover, #advanced_search_button span:hover{
background-position: 100% -22px !important;
}
When I hover over the part of the div which contains the , (the majority of the icon) then both parts of my sprite have the "hover" style applied to it. However, if I hover over the part of the image before the " I only see a chuck of the image have the "hover" style applied to it.
What I would like to be able to do is to activate the "hover" style for the span whenever the parent div has it's hover style applied to it.
Any advice?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试过
#search_tips:hover span
吗?Have you tried
#search_tips:hover span
?对于初学者来说,当您将鼠标悬停在某个项目上时,只有该项目会获得悬停 CSS 事件,而不是其后面的任何内容。
但是您可以在悬停时隐藏该元素,这会触发其后面的元素悬停。
For starters, when you hover over an item, only that item gets the hover css event, not anything behind it.
However you can hide the element on hover, which triggers hover for the element behind it.
不能 100% 确定它是否回答了您的问题,但
:hover
也可以是父选择器:这些规则将在
search_tips
出现时两者应用盘旋在上空。Not 100% sure whether it answers your question, but
:hover
can be a parent selector too:those rules will both apply the moment
search_tips
is hovered over.确保在 span 元素之前使用
:hover
伪类以使悬停正常工作:我还认为您需要使用
doc_button_left.png
作为如果您使用标准滑动门技术,则为span
的背景。我对此不是 100% 确定,但如果您仍然遇到问题,您可能需要进行更改。Make sure you use the
:hover
pseudo-class before the span element to make the hover work correctly:I also think you'll need to use your
doc_button_left.png
as the background of thespan
if you're using the standard sliding doors technique. I'm not 100% sure about this, but if you keep having problems, you might want to make that switch.