1

I have this navbar in all of bootstrap:

.navbar {
  background-color: aqua;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css">
  <link rel="stylesheet" href="bootstrap.min.css">
  <link rel="stylesheet" href="boot.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
  <script src="boot.js"></script>
</head>

<body>
  <div class="container-fluid">
    <nav class="navbar navbar-expand-md bg-dark navbar-dark">
      <a class="navbar-brand" href="#">Navbar</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
              <span class="navbar-toggler-icon"></span>
            </button>
      <div class="collapse navbar-collapse" id="collapsibleNavbar">
        <ul class="navbar-nav">
          <li class="nav-item active">
            <a class="nav-link" href="#">Subjects</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">About</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Contact</a>
          </li>
        </ul>
      </div>
    </nav>
  </div>
</body>

</html>
My problem is when i have the code in my boot.css file:

The background of the navbar is still the dark colour that was implemented in the nav tag. How can I override bootstrap css styling and customise my own.

Akshay Mulgavkar
  • 1,727
  • 9
  • 22
user218030
  • 107
  • 3
  • 12

3 Answers3

1

You have to remove the bg-dark class from the <navbar> element, and replace it with one of the bootstrap background color classes, like .bg-primary or some other color. For example:

<nav class="navbar navbar-expand-md bg-primary navbar-dark">      

Or you can make your own, such as:

.bg-aqua {
    background-color: aqua !important;
}

and add it as a class to the <navbar>:

<nav class="navbar navbar-expand-md bg-aqua navbar-light">

Note: the navbar-dark and navbar-light classes will make the text in your navbar white or black, depending on which one you choose.

Here is the Bootstrap Navbar Color Scheme documentatation here.

Bryan Elliott
  • 4,055
  • 2
  • 21
  • 22
0

You could try changing the color by using id. If you want to change many elements at once this may not be the best solution for you tho.

Simply add the id of your choice in this line (id="navigationID in this example):

 <nav class="navbar navbar-expand-md bg-dark navbar-dark" id="navigationID">

Then declare the background color you want in css for this id:

#navigationID{
  background-color:aqua !important;
}

Here is a working version of what i'm talking about

https://jsfiddle.net/q6fb7k5o/

b10z
  • 88
  • 1
  • 7
0

bootstrap bg-dark has there own style with !important so that if you want to override bootstrap style you have to put more specification than bootstrap style or you can remove those bootstrap style. see below details,

How can I override Bootstrap CSS styles?

NIKHIL CHANDRA ROY
  • 807
  • 11
  • 16