Skip to content
Fix Code Error

Change navbar color in Twitter Bootstrap

March 13, 2021 by Code Error
Posted By: Anonymous

How would I go about modifying the CSS to change the color of the navbar in Twitter Bootstrap?

Solution

tl;dr – TWBSColor – Generate your own Bootstrap navbar

Version notes:
– Online tool: Bootstrap 3.3.2+ / 4.0.0+
– This answer: Bootstrap 3.0.x

Available navbars

You’ve got two basic navbars:

<!-- A light one -->
<nav class="navbar navbar-default" role="navigation"></nav>
<!-- A dark one -->
<nav class="navbar navbar-inverse" role="navigation"></nav>

Default color usage

Here are the main colors and their usage:

  • #F8F8F8: navbar background
  • #E7E7E7: navbar border
  • #777: default color
  • #333: hover color (#5E5E5E for .nav-brand)
  • #555: active color
  • #D5D5D5: active background

Default style

If you want to put some custom style, here’s the CSS you need to change:

/* navbar */
.navbar-default {
    background-color: #F8F8F8;
    border-color: #E7E7E7;
}
/* Title */
.navbar-default .navbar-brand {
    color: #777;
}
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-brand:focus {
    color: #5E5E5E;
}
/* Link */
.navbar-default .navbar-nav > li > a {
    color: #777;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
    color: #333;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
    color: #555;
    background-color: #E7E7E7;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
    color: #555;
    background-color: #D5D5D5;
}
/* Caret */
.navbar-default .navbar-nav > .dropdown > a .caret {
    border-top-color: #777;
    border-bottom-color: #777;
}
.navbar-default .navbar-nav > .dropdown > a:hover .caret,
.navbar-default .navbar-nav > .dropdown > a:focus .caret {
    border-top-color: #333;
    border-bottom-color: #333;
}
.navbar-default .navbar-nav > .open > a .caret,
.navbar-default .navbar-nav > .open > a:hover .caret,
.navbar-default .navbar-nav > .open > a:focus .caret {
    border-top-color: #555;
    border-bottom-color: #555;
}
/* Mobile version */
.navbar-default .navbar-toggle {
    border-color: #DDD;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
    background-color: #DDD;
}
.navbar-default .navbar-toggle .icon-bar {
    background-color: #CCC;
}
@media (max-width: 767px) {
    .navbar-default .navbar-nav .open .dropdown-menu > li > a {
        color: #777;
    }
    .navbar-default .navbar-nav .open .dropdown-menu > li > a:hover,
    .navbar-default .navbar-nav .open .dropdown-menu > li > a:focus {
          color: #333;
    }
}

Custom colored navbar examples

Here are four examples of a custom colored navbar:

Enter image description here

And the SCSS code:

$bgDefault   : #e74c3c;
$bgHighlight : #c0392b;
$colDefault  : #ecf0f1;
$colHighlight: #ffbbbc;
.navbar-default {
  background-color: $bgDefault;
  border-color: $bgHighlight;
  .navbar-brand {
    color: $colDefault;
    &:hover, &:focus {
      color: $colHighlight; }}
  .navbar-text {
    color: $colDefault; }
  .navbar-nav {
    > li {
      > a {
        color: $colDefault;
        &:hover,  &:focus {
          color: $colHighlight; }}}
    > .active {
      > a, > a:hover, > a:focus {
        color: $colHighlight;
        background-color: $bgHighlight; }}
    > .open {
      > a, > a:hover, > a:focus {
        color: $colHighlight;
        background-color: $bgHighlight; }}}
  .navbar-toggle {
    border-color: $bgHighlight;
    &:hover, &:focus {
      background-color: $bgHighlight; }
    .icon-bar {
      background-color: $colDefault; }}
  .navbar-collapse,
  .navbar-form {
    border-color: $colDefault; }
  .navbar-link {
    color: $colDefault;
    &:hover {
      color: $colHighlight; }}}
@media (max-width: 767px) {
  .navbar-default .navbar-nav .open .dropdown-menu {
    > li > a {
      color: $colDefault;
      &:hover, &:focus {
        color: $colHighlight; }}
    > .active {
      > a, > a:hover, > a:focus, {
        color: $colHighlight;
        background-color: $bgHighlight; }}}
}

And finally, a little gift

I’ve just made a script which will allow you to generate your theme:
TWBSColor – Generate your own Bootstrap navbar

[Update]: TWBSColor now generates SCSS/SASS/Less/CSS code.
[Update]: From now, you can use Less as the default language provided by TWBSColor
[Update]: TWBSColor now supports drop down menus colorization
[Update]: TWBSColor now allows to choose your version (Bootstrap 4 support added)

Answered By: Anonymous

Related Articles

  • Fix top buttons on scroll of list below
  • Navbar not filling width of page when reduced to mobile view
  • don't know what went wrong nav bar with Tailwind CSS…
  • SQL query return data from multiple tables
  • Having trouble with my nav bar/header, It used to…
  • After a little scroll, the sticky navbar just is not…
  • Decreasing height of bootstrap 3.0 navbar
  • Active tab issue on page load HTML
  • How to show title in hover - css / jquery
  • Bootstrap 3 navbar active li not changing background-color
  • The theme changer for my code does not seem to work
  • How to create hyperlink to call phone number on…
  • How to implement a Navbar Dropdown Hover in Bootstrap v4?
  • Bootstrap 4 align navbar items to the right
  • Login with facebook android sdk app crash API 4
  • Keeping the User logged in
  • How do I keep only the first map and when the game…
  • Why does I can't add background image even I use static
  • Text color of nav bar items not reflecting custom CSS
  • Collapse 2nd navbar links to 1st navbar
  • How to Fix hover not working after JS script…
  • CSS Input with width: 100% goes outside parent's bound
  • Increasing size of semi circle using css
  • Stacked Tabs in Bootstrap 3
  • How to use if else if in button - flutter
  • How to make a SIMPLE C++ Makefile
  • If object of a nested array in mongodb doesn't have…
  • How do i update a javascript variable as its value changes?
  • center 3 items on 2 lines
  • Find the nth element in vue-test-utils
  • How to VueJS router-link active style
  • How to design a controller in Backbone.js?
  • Is it possible to move my text side by side with my icon
  • Reset/remove CSS styles for element only
  • Daisy is overlapping the other contents of the div
  • Centering in CSS Grid
  • custom text position on ipywidgets button
  • Trouble with boxes appearing/hiding based on selection
  • Simplest PHP example for retrieving user_timeline…
  • Changing Icon Color behind ListTile in an…
  • How do you get string interpolation working on a…
  • Bootstrap - center child when parent isn't centered…
  • Matplotlib scatter plot legend
  • vuetify change theme to a custom one
  • React Multi-level push menu SCSS Back button not working
  • How to add hamburger menu in bootstrap
  • Bootstrap Carousel Full Screen
  • Can't change html class when i click button in…
  • Bootstrap 4.6 + CSS, how to bottom align a row
  • Azure Sql : Unable to Replace HTML String
  • Jquery fadeToggle Trouble
  • bootstrap 4 .active class not changing on click
  • SVG shape alignment in CSS
  • Bootstrap full responsive navbar with logo or brand…
  • Problem in navigation bar as Im not able to make it…
  • How to hide collapsible Bootstrap 4 navbar on click
  • Trying to keep dropdown menus flush to the edge of…
  • Changing CSS variable based on the parent class ||…
  • How do I do a drag and drop using jQuery to move…
  • For loop variable doesn't work in an if condition in…
  • how to access parent component scope from a child…
  • How to use Bootstrap-Vue with a custom navbar…
  • How to increase space between dotted border dots
  • Unresponsive hamburger icon in HTML
  • How to pass TypeScript constants to Vue templates…
  • Adobe XD to responsive html
  • Align nav-items to right side in bootstrap-4
  • Drop-down menu that opens up/upward with pure css
  • Change background color on mouseover and remove it…
  • Named colors in matplotlib
  • I cant get my type writer heading to the center of my code
  • Content showing over the top of tooltip
  • Navbar Toggle button is not working and it's only…
  • Bootstrap 4 Change Hamburger Toggler Color
  • How can can ı resize an image which is into a card?
  • Bootstrap shadow not displaying on nav.shadow
  • how to create separate box for each category in flutter
  • How to add multiple light effects on a pane?
  • Split JSON python string to pass to function
  • Change bootstrap navbar background color and font color
  • Flutter - Insert a Listview between two fixed containers
  • Style jQuery autocomplete in a Bootstrap input field
  • How to stretch the div to all the height of the page?
  • How to add a div with bootstrap form elements dynamically?
  • VueJS - v-bind:style + hover
  • How should I deal with "package '✘✘✘' is not…
  • How do I count unique visitors to my site?
  • HTML drop-down menu with icons and text
  • Polymer 1.0 'array-style' path accessors,…
  • How to enable dark mode with custom colors in light…
  • Adding multiple dropdown menu's next to each other…
  • vue js cant understand keep alive
  • how to add data to a user's profile while not…
  • Bootstrap 4: Multilevel Dropdown Inside Navigation
  • Room @Relation with two foreign keys
  • Vuetify Navigation Drawer works once then stops
  • Vue Js - How to get slug from url?
  • CSS not applied to Polymer 2 web component in Chrome
  • Center an element in Bootstrap 4 Navbar
  • Bootstrap dropdown sub menu missing

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I check if a file exists in Java?

Next Post:

How to get a date in YYYY-MM-DD format from a TSQL datetime field?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error