如果链接处于活动状态,则React-router / CSS无悬停样式

时间:2017-10-27 22:22:55

标签: javascript css react-router react-router-v4

我使用react-router v4设置了样式导航。使用此代码根据悬停和活动作品更改样式。但是,如果我将鼠标悬停在(react-router)活动链接上,我确实想要禁用悬停样式。我怎样才能做到这一点?

这是我目前的代码:

  <div className="App-navbar">
    <NavLink className="inactive" activeClassName="activeLink" exact to="/">
      Home
    </NavLink>
    <NavLink className="inactive" activeClassName="activeLink" to="/about-us">
      About
    </NavLink>
  </div>

.App-navbar > a {
  display: inline-block;
  color: rgb(54, 127, 175);
}

.App-navbar > .inactive {
  text-decoration: none;
  font-size: 20px;
}

.App-navbar > .activeLink {
  color: rgb(0, 0, 0);
  background-color: rgba(54, 129, 175, 1);
  border-radius: 2px;
}

.App-navbar > a:hover {
  background-color: rgba(54, 129, 175, 0.2);
}

1 个答案:

答案 0 :(得分:0)

试试这个:

.App-navbar > a:not(.activeLink):hover {
  background-color: rgba(54, 129, 175, 0.2);
}
相关问题