简体   繁体   English

鼠标悬停隐藏的背景图片 <ul><li> 标签

[英]Mouse hover hides background image of <ul> <li> tabs

I have simple HTML <ul> and <li> tabs with some CSS applied on jsfiddle here . 我有简单的HTML <ul><li>选项卡,并在jsfiddle上应用了一些CSS

Basically, each tab has the format (please check the code linked above for more detail): 基本上,每个标签都有格式(请检查上面链接的代码以获取更多详细信息):

...
<li class="icons ...">
  <a href="#"></a>
<li>
...

As you saw in the code, the icon on each tab is actually the background image of each <li> element. 如您在代码中所看到的,每个选项卡上的图标实际上是每个<li>元素的背景图像

When the mouse hovers on a tab, I would like to also change the background color or background image of the <a> element. 鼠标悬停在选项卡上时,我还要更改 <a>元素的背景颜色或背景图像 When I try to do this, mouse hover then hides the tab image ( <li> background-image). 当我尝试执行此操作时, 鼠标悬停然后隐藏选项卡图像( <li>背景图像)。 How can I get rid of it? 我该如何摆脱呢?

----------Another way to say my problem------------------------ ----------表达我的问题的另一种方式------------------------

What I mean is I have already had a background-image for <li> element, then I also want to have a background-image for <a> element which is contained by <li> , but if I did so (that's have both <li> and <a> has background-image with also :hover background-image ), the background-image of <a> will hide the background-image of <li> , how to get rid of this problem? 我的意思是我已经有<li>元素的background-image ,然后我也想有<li> 包含的 <a>元素的background-image ,但是如果我这样做了( <li><a>background-image与也:hover background-image )时, background-image<a>将隐藏background-image<li>如何摆脱这个问题?

-------------Please check @ hradac 's reply, he understands my question correctly--------- -------------请检查@ hradac的回复,他正确理解了我的问题---------

Change the background-color of the LI containing your A instead. 更改包含A的LI的背景颜色。
That way your background-image won't be hidden by the A background-color. 这样,您的背景图片就不会被A背景颜色隐藏。
See http://jsfiddle.net/Pq7LC/21/ 参见http://jsfiddle.net/Pq7LC/21/

Remove this part from your css: 从CSS中删除此部分:

a:hover
{
    color: #ffffff;
    background-color: #990000;
}

http://jsfiddle.net/ryZ4j/2/ http://jsfiddle.net/ryZ4j/2/

From what I can gather you would like to have a background image in an <li> and a background image in an <a> contained in it. 据我所知,您希望在<li>包含背景图像,并在其中包含<a>中的背景图像。 Your code does not have any background images for the contained <a> tags. 您的代码没有所包含的<a>标记的任何背景图片。 All of your :hover switching happens on the <li> elements. 您所有的:hover切换都发生在<li>元素上。

The problem seems to be a layering issue. 这个问题似乎是一个分层的问题。 When you apply a background color to the contained <a> tags you can no longer see the background image of the <li> it is on top of. 当您将背景色应用于包含的<a>标记时,您将不再看到<li>的背景图像,它位于其上方。 The background images are still there, you just can't see them. 背景图像仍然存在,您只是看不到它们。 I suggest changing the background color of the <li> on :hover and leaving the background color of the <a> on transparent. 我建议在:hover上更改<li>的背景颜色,并在透明状态下保留<a>的背景颜色。 That way you can still see the <li> background image. 这样,您仍然可以看到<li>背景图像。

See an example here: http://jsfiddle.net/vzxGr/1/ 在此处查看示例: http : //jsfiddle.net/vzxGr/1/

Is this more like what you were looking for? 这更像您想要的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM