Change navbar color in Twitter Bootstrap

后端 未结 12 2021
悲&欢浪女
悲&欢浪女 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:24

    Just add an id to the HTML navbar, such as:

    With this id you can style the navbar color, but also the links and dropdowns

    Examples applied to different types of navbars

    Black

    Yellow

    Darkblue

    Red (Cherry)

    Darkgreen

    Here is the CSS

    /*
     * Black navbar style
     */
    #navbar-black.navbar-default { /* #3C3C3C - #222222 */
        font-size: 14px;
        background-color: rgba(34, 34, 34, 1);
        background: -webkit-linear-gradient(top, rgba(60, 60, 60, 1) 0%, rgba(34, 34, 34, 1) 100%);
        background: linear-gradient(to bottom, rgba(60, 60, 60, 1) 0%, rgba(34, 34, 34, 1) 100%);
        border: 0px;
        border-radius: 0;
    }
    #navbar-black.navbar-default .navbar-nav>li>a:hover,
    #navbar-black.navbar-default .navbar-nav>li>a:focus,
    #navbar-black.navbar-default .navbar-nav>li>ul>li>a:hover,
    #navbar-black.navbar-default .navbar-nav>li>ul>li>a:focus,
    #navbar-black.navbar-default .navbar-nav>.active>a,
    #navbar-black.navbar-default .navbar-nav>.active>a:hover,
    #navbar-black.navbar-default .navbar-nav>.active>a:focus {
        color: rgba(255, 255, 255, 1);
        background-color: rgba(0, 0, 0, 1);
        background: -webkit-linear-gradient(top, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 1) 100%);
        background: linear-gradient(to bottom, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 1) 100%);
    }
    #sidebar-black, #column-black {
          background-color: #222222;
    }
    #navbar-black.navbar-default .navbar-toggle {
        border-color: #222222;
    }
    #navbar-black.navbar-default .navbar-toggle:hover,
    #navbar-black.navbar-default .navbar-toggle:focus {
        background-color: #3C3C3C;
    }
    #navbar-black.navbar-default .navbar-nav>li>a,
    #navbar-black.navbar-default .navbar-nav>li>ul>li>a,
    #navbar-black.navbar-default .navbar-brand {
        color: #999999;
    }
    #navbar-black.navbar-default .navbar-toggle .icon-bar,
    #navbar-black.navbar-default .navbar-toggle:hover .icon-bar,
    #navbar-black.navbar-default .navbar-toggle:focus .icon-bar {
        background-color: #ffffff;
    }
    
    /*
     * Red navbar style
     */
    #navbar-red.navbar-default { /* #990033 - #cc0033 */
        font-size: 14px;
        background-color: rgba(153, 0, 51, 1);
        background: -webkit-linear-gradient(top, rgba(204, 0, 51, 1) 0%, rgba(153, 0, 51, 1) 100%);
        background: linear-gradient(to bottom, rgba(204, 0, 51, 1) 0%, rgba(153, 0, 51, 1) 100%);
        border: 0px;
        border-radius: 0;
    }
    #navbar-red.navbar-default .navbar-nav>li>a:hover,
    #navbar-red.navbar-default .navbar-nav>li>a:focus,
    #navbar-red.navbar-default .navbar-nav>li>ul>li>a:hover,
    #navbar-red.navbar-default .navbar-nav>li>ul>li>a:focus,
    #navbar-red.navbar-default .navbar-nav>.active>a,
    #navbar-red.navbar-default .navbar-nav>.active>a:hover,
    #navbar-red.navbar-default .navbar-nav>.active>a:focus {
        color: rgba(51, 51, 51, 1);
        background-color: rgba(255, 255, 255, 1);
        background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
        background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
    }
    #sidebar-red, #column-red {
          background-color: #990033;
    }
    #navbar-red.navbar-default .navbar-toggle {
        border-color: #990033;
    }
    #navbar-red.navbar-default .navbar-toggle:hover,
    #navbar-red.navbar-default .navbar-toggle:focus {
        background-color: #cc0033;
    }
    #navbar-red.navbar-default .navbar-nav>li>a,
    #navbar-red.navbar-default .navbar-nav>li>ul>li>a,
    #navbar-red.navbar-default .navbar-brand {
        color: #999999;
    }
    #navbar-red.navbar-default .navbar-toggle .icon-bar,
    #navbar-red.navbar-default .navbar-toggle:hover .icon-bar,
    #navbar-red.navbar-default .navbar-toggle:focus .icon-bar {
        background-color: #ffffff;
    }
    
    /*
     * Darkblue navbar style
     */
    #navbar-darkblue.navbar-default { /* #003399 - #0033cc */
        font-size: 14px;
        background-color: rgba(51, 51, 153, 1);
        background: -webkit-linear-gradient(top, rgba(51, 51, 204, 1) 0%, rgba(51, 51, 153, 1) 100%);
        background: linear-gradient(to bottom, rgba(51, 51, 204, 1) 0%, rgba(51, 51, 153, 1) 100%);
        border: 0px;
        border-radius: 0;
    }
    #navbar-darkblue.navbar-default .navbar-nav>li>a:hover,
    #navbar-darkblue.navbar-default .navbar-nav>li>a:focus,
    #navbar-darkblue.navbar-default .navbar-nav>li>ul>li>a:hover,
    #navbar-darkblue.navbar-default .navbar-nav>li>ul>li>a:focus,
    #navbar-darkblue.navbar-default .navbar-nav>.active>a,
    #navbar-darkblue.navbar-default .navbar-nav>.active>a:hover,
    #navbar-darkblue.navbar-default .navbar-nav>.active>a:focus {
        color: rgba(51, 51, 51, 1);
        background-color: rgba(255, 255, 255, 1);
        background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
        background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
    }
    #sidebar-darkblue, #column-darkblue {
        background-color: #333399;
    }
    #navbar-darkblue.navbar-default .navbar-toggle {
        border-color: #333399;
    }
    #navbar-darkblue.navbar-default .navbar-toggle:hover,
    #navbar-darkblue.navbar-default .navbar-toggle:focus {
        background-color: #3333cc;
    }
    #navbar-darkblue.navbar-default .navbar-nav>li>a,
    #navbar-darkblue.navbar-default .navbar-nav>li>ul>li>a,
    #navbar-darkblue.navbar-default .navbar-brand {
        color: #999999;
    }
    #navbar-darkblue.navbar-default .navbar-toggle .icon-bar,
    #navbar-darkblue.navbar-default .navbar-toggle:hover .icon-bar,
    #navbar-darkblue.navbar-default .navbar-toggle:focus .icon-bar {
        background-color: #ffffff;
    }
    
    /*
     * Darkgreen navbar style
     */
    #navbar-darkgreen.navbar-default { /* #006633 - #009933 */
        font-size: 14px;
        background-color: rgba(0, 102, 51, 1);
        background: -webkit-linear-gradient(top, rgba(0, 153, 51, 1) 0%, rgba(0, 102, 51, 1) 100%);
        background: linear-gradient(to bottom, rgba(0, 153, 51, 1) 0%, rgba(0, 102, 51, 1) 100%);
        border: 0px;
        border-radius: 0;
    }
    #navbar-darkgreen.navbar-default .navbar-nav>li>a:hover,
    #navbar-darkgreen.navbar-default .navbar-nav>li>a:focus,
    #navbar-darkgreen.navbar-default .navbar-nav>li>ul>li>a:hover,
    #navbar-darkgreen.navbar-default .navbar-nav>li>ul>li>a:focus,
    #navbar-darkgreen.navbar-default .navbar-nav>.active>a,
    #navbar-darkgreen.navbar-default .navbar-nav>.active>a:hover,
    #navbar-darkgreen.navbar-default .navbar-nav>.active>a:focus {
        color: rgba(51, 51, 51, 1);
        background-color: rgba(255, 255, 255, 1);
        background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
        background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
    }
    #sidebar-darkgreen, #column-darkgreen {
        background-color: #006633;
    }
    #navbar-darkgreen.navbar-default .navbar-toggle {
        border-color: #006633;
    }
    #navbar-darkgreen.navbar-default .navbar-toggle:hover,
    #navbar-darkgreen.navbar-default .navbar-toggle:focus {
        background-color: #009933;
    }
    #navbar-darkgreen.navbar-default .navbar-nav>li>a,
    #navbar-darkgreen.navbar-default .navbar-nav>li>ul>li>a,
    #navbar-darkgreen.navbar-default .navbar-brand {
        color: #999999;
    }
    #navbar-darkgreen.navbar-default .navbar-toggle .icon-bar,
    #navbar-darkgreen.navbar-default .navbar-toggle:hover .icon-bar,
    #navbar-darkgreen.navbar-default .navbar-toggle:focus .icon-bar {
        background-color: #ffffff;
    }
    
    /*
     * Yellow navbar style
     */
    #navbar-yellow.navbar-default { /* #99ff00 - #ccff00 */
        font-size: 14px;
        background-color: rgba(153, 255, 0, 1);
        background: -webkit-linear-gradient(top, rgba(204, 255, 0, 1) 0%, rgba(153, 255, 0, 1) 100%);
        background: linear-gradient(to bottom, rgba(204, 255, 0, 1) 0%, rgba(153, 255, 0, 1) 100%);
        border: 0px;
        border-radius: 0;
    }
    #navbar-yellow.navbar-default .navbar-nav>li>a:hover,
    #navbar-yellow.navbar-default .navbar-nav>li>a:focus,
    #navbar-yellow.navbar-default .navbar-nav>li>ul>li>a:hover,
    #navbar-yellow.navbar-default .navbar-nav>li>ul>li>a:focus,
    #navbar-yellow.navbar-default .navbar-nav>.active>a,
    #navbar-yellow.navbar-default .navbar-nav>.active>a:hover,
    #navbar-yellow.navbar-default .navbar-nav>.active>a:focus {
        color: rgba(51, 51, 51, 1);
        background-color: rgba(255, 255, 255, 1);
        background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
        background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
    }
    #sidebar-yellow, #column-yellow {
        background-color: #99ff00;
    }
    #navbar-yellow.navbar-default .navbar-toggle {
        border-color: #99ff00;
    }
    #navbar-yellow.navbar-default .navbar-toggle:hover,
    #navbar-yellow.navbar-default .navbar-toggle:focus {
        background-color: #ccff00;
    }
    #navbar-yellow.navbar-default .navbar-nav>li>a,
    #navbar-yellow.navbar-default .navbar-nav>li>ul>li>a,
    #navbar-yellow.navbar-default .navbar-brand {
        color: #999999;
    }
    #navbar-yellow.navbar-default .navbar-toggle .icon-bar,
    #navbar-yellow.navbar-default .navbar-toggle:hover .icon-bar,
    #navbar-yellow.navbar-default .navbar-toggle:focus .icon-bar {
        background-color: #ffffff;
    }
    

提交回复
热议问题