Change navbar color in Twitter Bootstrap

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

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

12条回答
  •  萌比男神i
    2020-11-22 00:34

    Update 2020

    Changing the Navbar color is different (and a little easier) in Bootstrap 4. You can create a custom navbar class, and then reference it to change the navbar without impacting other Bootstrap navs..

    
    

    Bootstrap 4.3+

    The CSS required to change the Navbar is much less in Bootstrap 4...

    .navbar-custom {
        background-color: #ff5500;
    }
    /* change the brand and text color */
    .navbar-custom .navbar-brand,
    .navbar-custom .navbar-text {
        color: rgba(255,255,255,.8);
    }
    /* change the link color */
    .navbar-custom .navbar-nav .nav-link {
        color: rgba(255,255,255,.5);
    }
    /* change the color of active or hovered links */
    .navbar-custom .nav-item.active .nav-link,
    .navbar-custom .nav-item:hover .nav-link {
        color: #ffffff;
    }
    

    Bootstrap 4 Custom Navbar Demo

    Changing the active/hover link background color also works with the same CSS, but you must adjust the padding if you want the bg color to fill the full height of the link...

    py-0 to remove vertical padding from the entire navbar...

    /* change the link color and padding  */
    .navbar-custom .navbar-nav .nav-link {
        color: rgba(255,255,255,.5);
        padding: .75rem 1rem;
    }
    
    /* change the color and background color of active links */
    .navbar-custom .nav-item.active .nav-link,
    .navbar-custom .nav-item:hover .nav-link {
        color: #ffffff;
        background-color: #333;
    }
    

    Bootstrap 4 Change Link and Background Color Demo

    Also see: Bootstrap 4 Change Hamburger Toggler Color


    **Bootstrap 3**
    
    
    
    .navbar-custom {
        background-color:#229922;
        color:#ffffff;
        border-radius:0;
    }
      
    .navbar-custom .navbar-nav > li > a {
        color:#fff;
    }
    
    .navbar-custom .navbar-nav > .active > a {
        color: #ffffff;
        background-color:transparent;
    }
          
    .navbar-custom .navbar-nav > li > a:hover,
    .navbar-custom .navbar-nav > li > a:focus,
    .navbar-custom .navbar-nav > .active > a:hover,
    .navbar-custom .navbar-nav > .active > a:focus,
    .navbar-custom .navbar-nav > .open >a {
        text-decoration: none;
        background-color: #33aa33;
    }
         
    .navbar-custom .navbar-brand {
        color:#eeeeee;
    }
    .navbar-custom .navbar-toggle {
        background-color:#eeeeee;
    }
    .navbar-custom .icon-bar {
        background-color:#33aa33;
    }
    

    Custom Navbar Demo on Bootply


    If the Navbar has dropdowns, add the following to change dropdown color(s):

    /* for dropdowns only */
    .navbar-custom .navbar-nav .dropdown-menu  { 
      background-color: #33aa33;
    }
    .navbar-custom .navbar-nav .dropdown-menu>li>a  { 
      color: #fff;
    }
    .navbar-custom .navbar-nav .dropdown-menu>li>a:hover,.navbar-custom .navbar-nav .dropdown-menu>li>a:focus  { 
      color: #33aa33;
    }
    

    Demo with Dropdown


    If you want to change the theme colors all together (beyond the navbar), see this answer

提交回复
热议问题