简体   繁体   English

鼠标悬停背景图片

[英]Mouse hover background image

I was wondering if there is anything which will make my nav menu on hover disappear and bring up a background image behind the menu on which the mouse is. 我想知道是否有什么可以使我的悬停导航菜单消失并在鼠标所在菜单后面显示背景图像。

I have a simple nav menu as follows: 我有一个简单的导航菜单,如下所示:

    <ul id="nav" class="group">
    <li><a href="#" id="nav-portfolio">portfolio</a></li>
    <li><a href="#" id="nav-blog">blog</a></li>
    <li><a href="#" id="nav-me">me</a></li>
    <li><a href="#" id="nav-contact">contact</a></li>
    </ul>

And the CSS for it is: 它的CSS是:

#nav {
    float: right;
    margin: 0.9em 1.5em 1em 0.9em;
    padding-right: 2em;

}

#nav li {

    float: left;
    padding: 0 0 0 .9em;
}

Yea, you can use :hover for this: 是的,您可以使用:hover

#nav li:hover {
    background: url("image.png") center center no-repeat;
}

If the image is already behind the menu, you just need to make the menu or the active option to disappear. 如果图像已经在菜单后面,则只需使菜单或活动选项消失即可。

In your code there is no image, but in any case, a code like this one should do the trick. 在您的代码中没有图像,但是无论如何,像这样的代码应该可以解决问题。

#nav li:hover a { color:transparent; }
#nav li:hover { background: url("image.jpg"); }

Bye 再见

例如,您使用不带单个婴儿床的url并使用绝对地址

#nav li:hover { background: url(/yourRootAddress/YourFileOrFolderImage/image.jpg); }

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

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