简体   繁体   English

将鼠标悬停在上方时更改图像颜色

[英]Change image color when hovering over li

I am trying to create a menu where each links has an image/icon right next to it. 我试图创建一个菜单,每个链接旁边都有一个图像/图标。 I'd like the image to be black and white when it's inactive, but to be in color when i'm hovering over the image and the text. 我希望图像处于非活动状态时为黑白,但是当我将鼠标悬停在图像和文本上时为彩色。

I'v tried to use an .svg as explained in another question ( https://stackoverflow.com/a/4028908/3334898 ), it works but only when i'm hovering over the image, not the text :/. 我试图按照另一个问题( https://stackoverflow.com/a/4028908/3334898 )中的说明使用.svg,它可以工作,但仅当我将鼠标悬停在图像上而不是文本:/时。

Here is the CSS for the images: 这是图像的CSS:

.nav img
{
    height: 30px;
    width: 30px;
    margin-right: 5px;
    filter: url(filters.svg#grayscale); /* Firefox 3.5+ */
    filter: gray; /* IE6-9 */
    -webkit-filter: grayscale(1); /* Google Chrome, Safari 6+ & Opera 15+ */
}

.nav img:hover 
{
    filter: none;
    -webkit-filter: grayscale(0);
}

And what the menu looks like : 菜单如下所示:

<div class="nav">

        <ul>

            <li id="home"><a href="index.php"><img src="menu/person.png">Présentation</a></li>
            <li id="formation"><a href="formation.php"><img src="menu/tablet.png">Formations</a></li>
            <li id="competence"><a href="competences.php"><img src="menu/etiquette.png">Compétences</a></li>
            <li id="experience"><a href="experiences.php"><img src="menu/work.png">Expériences</a></li>
            <li id="autre"><a href="autres.php"><img src="menu/autre.png">Autres</a></li>

        </ul>

    </div>

Thank you. 谢谢。

Change your CSS to 将您的CSS更改为

.nav a:hover img {
    filter: none;
    -webkit-filter: grayscale(0);
}

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

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