Home > Net >  how can I make the active tab highlighted until I change the tab for another?
how can I make the active tab highlighted until I change the tab for another?

Time:12-17

I created a simple vue app with router. I managed to get the tab highlighted upon hovering on it but I want it to stay coloured until the user changes for another. Here is relevant code:

<nav>
    <ul>
    <li><router-link to="/contact">Contact</router-link></li>
    <li><router-link to="/blog">Blog</router-link></li>
    <li><router-link to="/ceremonies">Ceremonies</router-link></li>
    <li><router-link to="/pregnancy">Pregnancy Yoga</router-link></li>
    <li><router-link to="/about">About</router-link></li>
    <li><router-link to="/">Home</router-link></li>
    


    </ul>
  </nav>
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color:#F1D0E5
}

li {
  float: right;
}

li a {
  font-size: 20px;
  display: block;
  color: #89a864;
  font-weight:900;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover {
  background-color:#985277;
}
li a:active {
    background-color:#985277;

}

it does not stay higlighted as soon as I remove the cursor

CodePudding user response:

vue-router automatically adds two classes to the active <router-link> component.

.router-link-active and .router-link-exact-active

You can use those classes to style your links.

This is a comprehensive answer that covers how/when these classes are applied.

  • Related