Change navbar color in Twitter Bootstrap

后端 未结 12 2014
悲&欢浪女
悲&欢浪女 2020-11-22 00:19

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

相关标签:
12条回答
  • 2020-11-22 00:34

    Example

    Just try it like this:

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

    File navabr.css

    /* 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;
        }
    }
    

    The default major color uses are as below:

    • Navbar Background: #F8F8F8
    • Navbar Border: #E7E7E7
    • Default Color: #777
    • Nav-brand Hover Color: #5E5E5E
    • Hover Color: #333
    • Active Background: #D5D5D5
    • Active Color: #555

    You can learn more in To change navbar color in Twitter Bootstrap 3.

    0 讨论(0)
  • 2020-11-22 00:37

    Try this too. This worked for me.

    .navbar-default .navbar-nav > li > a:hover,
    .navbar-default .navbar-nav > li > a:focus {
      background-color: #00a950;
      color: #000000;
    }
    
    0 讨论(0)
  • 2020-11-22 00:43

    It took me a while, but I discovered that including the following was what made it possible to change the navbar color:

    .navbar{ 
        background-image: none;
    }
    
    0 讨论(0)
  • 2020-11-22 00:43

    Using Less

    You could also consider to compile your own version. Try http://getbootstrap.com/customize/ (which has a apart section for the Navbars settings (Default navbar and Inverted Navbar)) or download your own copy from https://github.com/twbs/bootstrap.

    You will find the navbar settings in variables.less. navbar.less is used to compile the navbar (depends on variables.less and mixins.less).

    Copy the 'navbar-default section' and fill in your own color settings. Changing the variables in variables.less will be the easiest way (changing the default or inverse navbar won't be a problem because you have one navbar per page only).

    You won't change all settings in most cases:

    // Navbar
    // -------------------------
    
    // Basics of a navbar
    @navbar-height:                    50px;
    @navbar-margin-bottom:             @line-height-computed;
    @navbar-default-color:             #777;
    @navbar-default-bg:                #f8f8f8;
    @navbar-default-border:            darken(@navbar-default-bg, 6.5%);
    @navbar-border-radius:             @border-radius-base;
    @navbar-padding-horizontal:        floor(@grid-gutter-width / 2);
    @navbar-padding-vertical:          ((@navbar-height - @line-height-computed) / 2);
    
    // Navbar links
    @navbar-default-link-color:                #777;
    @navbar-default-link-hover-color:          #333;
    @navbar-default-link-hover-bg:             transparent;
    @navbar-default-link-active-color:         #555;
    @navbar-default-link-active-bg:            darken(@navbar-default-bg, 6.5%);
    @navbar-default-link-disabled-color:       #ccc;
    @navbar-default-link-disabled-bg:          transparent;
    
    // Navbar brand label
    @navbar-default-brand-color:               @navbar-default-link-color;
    @navbar-default-brand-hover-color:         darken(@navbar-default-link-color, 10%);
    @navbar-default-brand-hover-bg:            transparent;
    
    // Navbar toggle
    @navbar-default-toggle-hover-bg:           #ffffd;
    @navbar-default-toggle-icon-bar-bg:        #ccc;
    @navbar-default-toggle-border-color:       #ffffd;
    

    You could also try http://twitterbootstrap3navbars.w3masters.nl/. This tool generates CSS code for your custom navbar. Optionally, you could also add gradient colors and borders to the navbar.

    0 讨论(0)
  • 2020-11-22 00:43

    Do you have to change the CSS directly? What about...

    <nav class="navbar navbar-inverse" style="background-color: #333399;">
    <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="#">Logo</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Projects</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
    

    0 讨论(0)
  • 2020-11-22 00:44

    Inverse and default class name mention in Twitter Bootstrap cause them to be black and white color.

    Better, you should not override that and add a class near that and write you particular style for that:

    my_style{
        background-color: green;
    }

    0 讨论(0)
提交回复
热议问题