SoftTimur
SoftTimur

Reputation: 5510

Change the default background-color and hover background-color of navbar

I have the following bootstrap navbar: JSBin:

 <!DOCTYPE html>
    <html>
    <head>
      <script src="https://code.jquery.com/jquery.min.js"></script>
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
    </head>
    <body>
      <nav class="navbar navbar-default navbar-static-top" ng-controller="NavCtrl">
        <ul class="nav navbar-nav">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdow <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="https://www.google.fr">New</a></li>
              <li><a href="https://www.google.fr">Old</a></li>
            </ul>
          </li>
          <li><a href="https://www.google.fr">Help</a></li>
        </ul>
      </nav>
    </body>
    </html>

I want to do the following:

  1. change the default background color of the navbar to #e1e1e1
  2. when we hover on dropdown and help, the background color of that element becomes even darker (eg, #a9a9a9)

Does anyone know how to achieve this?

Upvotes: 0

Views: 2894

Answers (3)

Michael Coker
Michael Coker

Reputation: 53674

Target it with these rules to overwrite the default bootstrap styling.

.navbar-default {
    background-color: #e1e1e1;
}
.navbar-default .navbar-nav>li>a:focus, 
.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus, 
.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover  {
  background: #a9a9a9;
}

<!DOCTYPE html>
<html>
<head>
  <script src="https://code.jquery.com/jquery.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
  <style>
  .navbar-default {
    background-color: #e1e1e1;
}
nav.navbar-default .navbar-nav>li>a:focus, 
nav.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus, 
nav.navbar-default .navbar-nav>li>a:hover,
nav.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover {
  background: #a9a9a9;
}
</style>
</head>
<body>
  <nav class="navbar navbar-default navbar-static-top" ng-controller="NavCtrl">
    <ul class="nav navbar-nav">
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdow <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="https://www.google.fr">New</a></li>
          <li><a href="https://www.google.fr">Old</a></li>
        </ul>
      </li>
      <li><a href="https://www.google.fr">Help</a></li>
    </ul>
  </nav>
</body>
</html>

Upvotes: 2

Gerard
Gerard

Reputation: 15786

Is this what you need?

.nav li {
background: #e1e1e1;
}
.nav li:hover {
background: #a1a1a1;
}
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<body>
  <nav class="navbar navbar-default navbar-static-top" ng-controller="NavCtrl">
    <ul class="nav navbar-nav">
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdow <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="https://www.google.fr">New</a></li>
          <li><a href="https://www.google.fr">Old</a></li>
        </ul>
      </li>
      <li><a href="https://www.google.fr">Help</a></li>
    </ul>
  </nav>

Upvotes: 1

Alex Bieg
Alex Bieg

Reputation: 365

You just have to select the elements you wish to change

.navbar {
  background-color: #e1e1e1;
}

nav li:hover {
  background-color: #a9a9a9;
}

Upvotes: 1

Related Questions