Html 如何更改导航元素内的字体颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19616717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:47:33  来源:igfitidea点击:

How to change font color inside nav element?

htmlcsscolorsnav

提问by user2924752

I have a element and I want to change the color of the links within it, but all other links on my page are styled using the following CSS:

我有一个元素,我想更改其中链接的颜色,但我页面上的所有其他链接都使用以下 CSS 设置样式:

a:link {

    color:#22b14c;
    text-decoration:none;
    }

and here is the nav:

这是导航:

<nav id="Nav">
        <a href="index.html">Home</a> |
        <a href="Gallery.html">Library</a> |
        <a href="Contact.html">Contact</a> |
        <a href="About.html">About</a>
</nav>

and the nav css:

和导航 css:

#Nav {

    margin-top: 20px;
    background-color: #000000;
    color: #f2f2f2;
    font-size: 40px;
    font-family: "Calibri";
    text-align: center;
    }

I tried a span inside the nav element but that didn't work. How can I change the color for these links only inside the element?

我在导航元素内尝试了一个跨度,但这没有用。如何仅在元素内部更改这些链接的颜色?

回答by Rahul Tripathi

Are you looking for this:

你在找这个吗:

#Nav a{
     color: #f2f2f2;
     text-decoration:none;
}

#Nav a:hover {
    color: blue;
    text-decoration: underline;
}

回答by ZippyV

#Nav a {
    color: #f2f2f2;
}

#Nav a:hover {
    color: red;
    text-decoration: underline;
}