【问题标题】:Font Color Not Changing Even With !important [duplicate]即使使用 !important 字体颜色也不会改变 [重复]
【发布时间】:2019-05-18 22:55:50
【问题描述】:

我正在尝试更改活动导航栏项目的字体颜色,但它不会改变。但是,背景颜色确实发生了变化。

我尝试使用 !important 标记,将 style= 直接插入到标记中,并将 .active 类 css 代码放在样式表的顶部。这些都没有奏效。

p,
h1,
h2,
h3 {
  font-family: Georgia;
  color: #62666a;
}

.nav {
  width: 100%;
  text-align: center;
}

ul#navBar {
  list-style-type: none;
  margin: 0;
  border-radius: 4px;
  padding-left: 31%;
  overflow: hidden;
  background-color: white;
  position: relative;
  top: 0;
  text-align: center;
  box-shadow: 0px 3px 10px#888888;
}

li#navBar {
  float: left;
}

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

li#navBar a:hover {
  background-color: #004b65;
  color: white;
}

.active {
  background-color: #0084a2;
  color: #FFFFFF !important;
}

.site-footer {
  background: #e7e7ef;
  border-radius: 4px;
}

#footer-content {
  color: white;
  overflow: hidden;
}

#footer-left {
  float: left;
  padding-left: 1%;
}

#footer-right {
  float: right;
  padding-right: 1%;
}

.row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
}

.column {
  display: flex;
  flex-direction: column;
  flex-basis: 100%;
  flex: 1;
  text-align: left;
}

button {
  background-color: #0084a2;
  border-radius: 8px;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}

button:hover {
  background-color: #004b65;
}

.index-button {
  background-color: #e7e7ef;
  height: 100%;
  width: 100%;
  vertical-align: middle;
  align-content: center;
}

#index-button-content {
  padding: 10%;
  text-align: center;
}

.menu-content {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  padding: 3%;
  box-shadow: 0px 5px 10px#888888;
}
<div class="nav">
  <ul id="navBar">
    <li id="navBar" class="active"><a href="index.php">Home</a></li>
    <li id="navBar"><a href="menu.php">Menu</a></li>
    <li id="navBar"><a href="catering.php">Catering</a></li>
    <li id="navBar"><a href="about.php">About Us</a></li>
    <li id="navBar"><a href="contact.php">Contact</a></li>
  </ul>
</div>

我希望激活时背景颜色和字体颜色都发生变化,但现在只有背景颜色发生变化。

【问题讨论】:

  • 对于你需要定位的颜色a --> .active a

标签: html css


【解决方案1】:

您应该尝试使用更具体的 CSS 选择器,

.active {
  background-color: #0084a2;
  color: #FFFFFF !important;
}

应该是这样的:

li.active a{ /* change thiss selector */
  background-color: #0084a2;
  color: #FFFFFF !important;
}

p,
h1,
h2,
h3 {
  font-family: Georgia;
  color: #62666a;
}

.nav {
  width: 100%;
  text-align: center;
}

ul#navBar {
  list-style-type: none;
  margin: 0;
  border-radius: 4px;
  padding-left: 31%;
  overflow: hidden;
  background-color: white;
  position: relative;
  top: 0;
  text-align: center;
  box-shadow: 0px 3px 10px#888888;
}

li#navBar {
  float: left;
}

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

li#navBar a:hover {
  background-color: #004b65;
  color: white;
}

li.active a{ /* change thiss selector */
  background-color: #0084a2;
  color: #FFFFFF !important;
}

.site-footer {
  background: #e7e7ef;
  border-radius: 4px;
}

#footer-content {
  color: white;
  overflow: hidden;
}

#footer-left {
  float: left;
  padding-left: 1%;
}

#footer-right {
  float: right;
  padding-right: 1%;
}

.row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
}

.column {
  display: flex;
  flex-direction: column;
  flex-basis: 100%;
  flex: 1;
  text-align: left;
}

button {
  background-color: #0084a2;
  border-radius: 8px;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}

button:hover {
  background-color: #004b65;
}

.index-button {
  background-color: #e7e7ef;
  height: 100%;
  width: 100%;
  vertical-align: middle;
  align-content: center;
}

#index-button-content {
  padding: 10%;
  text-align: center;
}

.menu-content {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  padding: 3%;
  box-shadow: 0px 5px 10px#888888;
}
<div class="nav">
  <ul id="navBar">
    <li id="navBar" class="active"><a href="index.php">Home</a></li>
    <li id="navBar"><a href="menu.php">Menu</a></li>
    <li id="navBar"><a href="catering.php">Catering</a></li>
    <li id="navBar"><a href="about.php">About Us</a></li>
    <li id="navBar"><a href="contact.php">Contact</a></li>
  </ul>
</div>

【讨论】:

    猜你喜欢
    • 2021-06-25
    • 1970-01-01
    • 2020-07-07
    • 2021-09-30
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 2018-03-16
    • 2013-06-01
    相关资源
    最近更新 更多