gpt4 book ai didi

css - 为什么 :hover changes just background-color, 但不更改链接颜色?

转载 作者:行者123 更新时间:2023-11-27 23:17:13 27 4
gpt4 key购买 nike

我为网站做导航,当我尝试制作 :hover 时,它只改变背景颜色,但不改变链接的颜色,为什么?

我尝试了很多东西,但效果不佳。可能我犯了一些错误。

HTML:

<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="styles.css" rel="stylesheet">
<title>Document</title>
</head>
<body>
<ul>
<li><a href="#">Главная</a></li>
<li><a href="#">Новости</a></li>
<li><a href="#">Контакты</a></li>
<li><a href="#">О компании</a></li>
<li><a href="#">Как добраться</a></li>
</ul>
</body>
</html>

CSS:

ul {
color:blue;
list-style-type: none;
width: 200px;
padding: 0px;
margin: 0px;
}

a {
text-decoration: none;
}

li {
border: 1px solid blue;
padding: 7px 5px 8px 5px;
margin: 5px 0px 5px 0px;
font-family: Arial;
font-size: 13px;
font-weight: bold;
background-color: #3a3939;
border-color: black;
}

li:hover{ /* Here looks everything fine */
background-color: white;
cursor: pointer;
border-color: black;
color: black;
}

a:link, a:visited {
color: white;
}

最佳答案

更改 li:hover 上的颜色以更改文本颜色,但也将颜色设置为继承 a:link 本身

ul {
color:blue;
list-style-type: none;
width: 200px;
padding: 0px;
margin: 0px;
}

a {
text-decoration: none;
}

li {
border: 1px solid blue;
padding: 7px 5px 8px 5px;
margin: 5px 0px 5px 0px;
font-family: Arial;
font-size: 13px;
font-weight: bold;
background-color: #3a3939;
border-color: black;
}

li:hover{ /* Here looks everything fine */
background-color: white;
cursor: pointer;
border-color: black;
color: black; /* Add this here */
}

a:link, a:visited {
color: inherit; /* make this color reflect li:hover's color using inherit*/
}
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="styles.css" rel="stylesheet">
<title>Document</title>
</head>
<body>
<ul>
<li><a href="#">Главная</a></li>
<li><a href="#">Новости</a></li>
<li><a href="#">Контакты</a></li>
<li><a href="#">О компании</a></li>
<li><a href="#">Как добраться</a></li>
</ul>
</body>
</html>

关于css - 为什么 :hover changes just background-color, 但不更改链接颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58206684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com