更改“活动”的颜色

时间:2018-07-03 09:44:11

标签: html css

即使更改了rgb,活动颜色仍为白色。

.nav li>a:hover,
.nav .open>a:hover,
.nav li>a:focus,
.nav .open>a:focus,
.nav li>a:active,
.nav .open>a:active {
  background-color: rgb(255, 0, 0)
<nav class="navbar navbar-m2p sidebar" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-sidebar-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Foobar<b>Company</b></a>
   </div>
</nav>

2 个答案:

答案 0 :(得分:1)

使用nav并在navbar内部使用navbar a

.navbar a:hover,
.navbar .open>a:hover,
.navbar span>a:focus,
.navbar .open>a:focus,
.navbar a:active,
.navbar a:active {
  background-color: rgb(255, 0, 0)
<nav class="navbar navbar-m2p sidebar" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-sidebar-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Foobar<b>Company</b></a>
    </div>
  </div>
</nav>

答案 1 :(得分:0)

使用.navbar代替.nav ,我看不到任何li元素,因此将其从CSS中删除:

我建议您了解CSS中的选择器:https://www.w3schools.com/cssref/css_selectors.asp

.navbar a:hover,
.navbar a:focus,
.navbar a:active {
     background-color:rgb(255,0,0);
     }
<nav class="navbar navbar-m2p sidebar" role="navigation">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-sidebar-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">
                Foobar<b>Company</b>
            </a>
        </div>