0

I am trying to change the font color of my active navigation bar item but it will not change. However, the background color does change.

I have tried using the !important tag, inserting a style= directly into the tag, and putting my .active class css code at the top of my stylesheet. None of which has worked.

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>

I want both the background color and font color to change when active, but right now only the background color is changing.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Aidan Baker
  • 47
  • 1
  • 8

1 Answers1

0

you should try to use CSS Selector with more specificity,

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

should be like :

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>