如何在引导导航栏上添加背景悬停颜色?

时间:2019-02-03 15:32:57

标签: css html5 css3 twitter-bootstrap-3 bootstrap-4

当我将鼠标悬停在链接上时,我正在尝试为链接添加背景色 并在我也将其悬停时更改社交媒体图标的颜色。

我已经寻找并尝试了很多我寻找的答案,但是当我尝试时,它仍然对我不起作用。

有人可以帮忙吗?非常感谢

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#"> <img src="LOGO.png" class="img-responsive logo"></a>
  
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarText">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" href="#">Featured</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Brand new</a>
      </li>
    </ul>
    <a class="navbar-text" href="#">
      <img src="insta.png" width="30"height="30" alt="">
    </a>
    <a class="navbar-text" href="#">
      <img src="Twitter.png" width="30"height="30" alt="">
    </a>
    <a class="navbar-text" href="#">
      <img src="facebook.png" width="30"height="30" alt="">
    </a>
  </div>
</nav>

2 个答案:

答案 0 :(得分:0)

只需使用background-color选择器来更改悬停的菜单项的.nav-item:hover { background-color: red; } .navbar-text:hover { background-color: red; } 属性,如下所示:

.nav-item:hover {
  background-color: red;
}

检查并运行以下代码段,以获取上述代码的实际示例:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#"> <img src="//picsum.photos/50/50" class="img-responsive logo"></a>
  
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarText">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" href="#">Featured</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Brand new</a>
      </li>
    </ul>
    <a class="navbar-text" href="#">
      <img src="insta.png" width="30"height="30" alt="">
    </a>
    <a class="navbar-text" href="#">
      <img src="Twitter.png" width="30"height="30" alt="">
    </a>
    <a class="navbar-text" href="#">
      <img src="facebook.png" width="30"height="30" alt="">
    </a>
  </div>
</nav>
public class Sources  
{
   public long[] SourceIds;
}


string jsonstring = " [\r\n {\r\n  \"SourceIds\": 20181234\r\n  }, \r\n 
{\r\n  \"SourceIds\": 20181234\r\n  },\r\n {\r\n  \"SourceIds\": 
20181234\r\n  }\r\n]"

答案 1 :(得分:0)

尝试使用:hover

.nav-link:hover {
  background-color: #B10331;
}
.navbar-text:hover {
  background-color: #B10331;
}