html - 悬停时如何更改列表元素中文本的颜色?

标签 html css

body {
  text-align: center;
  background-color: #f5f5ef;
  color: #333;
  font-size: 18px;
  background: url(bgimage.jpeg);
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  /*background-color: #333;*/
}

li {
  float: center;
}

li a {
  display: inline-block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li:hover {
  background-color: #111;
}

li a:hover {
  color: white;
}
<!DOCTYPE html>
<html>

<head>
  <title>
    Test Website 1
  </title>
  <meta charset="utf-8">
  <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
  <link href="main.css" rel="stylesheet" type="text/css">
</head>

<body>
  <ul style="color:white">
    <li id="currency"><a href="CurrencyConverter/currency_converter.html">Currency Converter</a></li>
    <li id="feature2"><a href="Feature2/feature2.html">Feature2</a></li>
    <li id="about"><a href="About/about.html">About</a></li>
    <li id="contact"><a href="Contact/contact.html">Contact</li>
    	</ul>
    </body>
    </html>

这很难解释,但我希望即使鼠标悬停在“li”标签的水平空间上时文本也会改变颜色,而不仅仅是悬停在文本上时。我不知所措。请帮忙。

最佳答案

改变这个

li a:hover{
 color: white;
}

为此

li:hover a{
 color: white;
}

Fiddle

关于html - 悬停时如何更改列表元素中文本的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46310722/

相关文章:

jquery - 如何在覆盖 css 中定义的样式时更新属性?

html - 将鼠标悬停在带有 :before 的内联菜单中

html - 在 ShinyDashboardPlus 中完全折叠左侧边栏

html - 为什么 window.innerHeight > document.body.scrollHeight?

javascript - Bootstrap 3方 block 展示

python - 如何将 css 格式应用于 pd.DataFrame 而不显示索引列

javascript - iOS 8.3 Mobile Safari 禁用表情符号渲染

html - 如何使固定宽度的表格适合手机浏览器的整个宽度?

javascript - 有没有办法在滚动事件之前采取行动?

html - IE 显示问题 : Fieldset size not being determined by content, 和内联显示会导致其他问题