字体颜色即使使用!important也不会改变

时间:2019-05-18 14:39:58

标签: html css

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

我尝试使用!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>

我希望背景颜色和字体颜色在激活时都可以改变,但是现在只有背景颜色在改变。

1 个答案:

答案 0 :(得分:0)

您应该尝试更具体地使用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>