CSS 将鼠标悬停在列表上时如何更改锚点颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4358316/
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
How to change anchor color when you hover over a list
提问by shin
I have a following HTML and CSS.
我有以下 HTML 和 CSS。
When I hover over a list, I want to change the background color and font color. However my style does not change when I hover over padding of list, on the border or near a border inside the list.
当我将鼠标悬停在列表上时,我想更改背景颜色和字体颜色。但是,当我将鼠标悬停在列表的内边距、边框上或列表内的边框附近时,我的样式不会改变。
How can I do it?
我该怎么做?
#nav li{
display: inline;
text-align: center;
list-style-type:none;
background-color:#1A365B;
margin: 0 6px 0 0;
padding: 2px 11px 4px 11px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}
#nav li:hover{
background-color:#E0F1EA;
border: 2px solid #000;
color: #000000;
padding: 0 9px 2px 9px;
}
#nav li a:hover{
color: #000000;
}
#nav li a{
text-decoration: none;
color: #ffffff;
font-weight:bold;
font-family: 'CantarellBold', Arial, sans-serif;
text-transform: capitalize;
font-size: 12px;
}
<ul id="nav" class="grid_16">
<li><a href="#">FORSIDE</a></li>
<li><a href="#">MOBIL</a></li>
<li><a href="#">PC OG SERVERE</a></li>
<li><a href="#">TJENESTER</a></li>
</ul>
回答by Zain Shaikh
回答by heximal
it could seem strange, but try to place #nav li a:hover style before #nav li a
这可能看起来很奇怪,但请尝试将 #nav li a:hover 样式放在 #nav li a 之前