0

https://www.bootply.com/XzK3zrPhJJ

In this example, why is the Home button not marked red?

.navbar a:hover,
.navbar a:focus,
.navbar a:active {
  color: red !important;
}
<nav class="navbar navbar-expand-lg">
  <div class="collapse navbar-collapse">
    <div class="nav navbar-nav">
      <a href="/index.php" class="active">Home</a>
      <a href="#">Links</a>
      <a href="#">About</a>
    </div>
  </div>
</nav>

1
  • Just a typo: a.active instead of/in addition to a:active. Commented Sep 19, 2019 at 13:41

4 Answers 4

2

You shoud use not a:active but a.active

:after is a pseudo class. But you want to select a tags which also has .active class.

.navbar a:hover,
.navbar a:focus,
.navbar a.active {
  color: red !important;
}
<nav class="navbar navbar-expand-lg">
  <div class="collapse navbar-collapse">
    <div class="nav navbar-nav">
      <a href="/index.php" class="active">Home</a>
      <a href="#">Links</a>
      <a href="#">About</a>
    </div>
  </div>
</nav>

Sign up to request clarification or add additional context in comments.

Comments

1

Use the css Class selectors

The CSS class selector matches elements based on the contents of their class attribute.

.navbar a.active {
  color: red;
}
<nav class="navbar navbar-expand-lg">
  <div class="collapse navbar-collapse">
    <div class="nav navbar-nav">
      <a href="/index.php" class="active">Home</a>
      <a href="#">Links</a>
      <a href="#">About</a>
    </div>
  </div>
</nav>

keep in mind that The :hover CSS pseudo-class

The :hover CSS pseudo-class matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer).

and avoid !important you can read more about !important_exception here

Comments

0

Why is it not active, but with active CLASS

instead of a:active use .active to reference, in this case you can also read more about the selector HERE

Comments

-1

I think, it should be like this:

navbar a:hover {
color:red;
font-weight:bolder;
text-decoration:underline;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.