Fins Up
Fins Up

Reputation: 39

How to change the default-navbar background color

I used a template from bootstrap for my navbar. I am using the default-navbar class. I was wondering how I can change the background-color and other properties of this class in the css. Right now when I create a style with the class .navbar-default and try to change the background color, it doesn't work. I think I have to create a custom style sheet to overide this? If so, how do I do this, and where would I place the text for the custom style sheet, if that's what I have to do? Here's my code.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<nav class="navbar-default">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <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="#">Brand</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>

Upvotes: 1

Views: 20415

Answers (5)

Kmg Kumar
Kmg Kumar

Reputation: 616

Rewrite the navbar-header class into the following code and put the important in the code

.container-fluid>.navbar-collapse, .container-fluid>.navbar-header, .container>.navbar-collapse, .container>.navbar-header {
    margin-right: -15px;
    margin-left: -15px;
    background-color: blanchedalmond !important;
}

Upvotes: 0

Blues Clues
Blues Clues

Reputation: 1848

.navbar-default {
  background-color: #c11111 !important;
}

Upvotes: 0

KalyanLahkar
KalyanLahkar

Reputation: 855

You can either add a new class like navbar-custom and add the class in a custom.css and in custom.css

.navbar-custom { background-color: red !important; }

and in your markup write

<nav class="navbar navbar-custom">

or you can do

<nav class="navbar-default" style="background-color: red">

for example and replace red with whatever color you like

Upvotes: 5

Srajan Chansoriya
Srajan Chansoriya

Reputation: 7

If you have access and the editing-authorization to the style sheet (defined as the web address in the CSS code i.e. https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css) then only you will be able to change the desired parameters using background-image or background-color...otherwise that might not be possible!

Further you may also try opening that url address (where your CSS stylesheet has been saved i.e. https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.csson a browser, copying the CSS code to an IDE, editing the desired parameters and linking the css of your website to the newly created (edited) style sheet! This might work.

Upvotes: 0

user4447799
user4447799

Reputation:

Just add !important to the background-color.

.navbar-default {
  background-color: red !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<nav class="navbar-default">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <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="#">Brand</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>

Upvotes: 1

Related Questions