Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of active tabs

Using Bootstrap v2.3.2, I am trying to change the default background color for the active tabs. I've tried to set as below, but it doesn't work:

.nav-tabs > .active > a,
.nav-tabs > .active > a:hover,
.nav-tabs > .active > a:focus
{
    color: #555555;
    background-color: red;  
} 

Any advice as to why this isn't working, or how to fix it?

like image 305
DavidX Avatar asked Aug 02 '13 13:08

DavidX


People also ask

How do I change the tab background color in Windows 10?

To change the color of a sheet tab, right-click the tab, point to Tab Color and pick a color that you want. Tip: Click away from the formatted tab to see the new tab color. If you want to remove the color, right-click the tab, point to Tab Color, and pick No Color.

How do I change the active tab color in bootstrap?

You can always modify your navigation list through css. Use this css code instead, in that way use you use the a tag to change the color and its background-color. It's improper to use the li tag to set the background only and a tag to set the color of the text.


1 Answers

In the Bootstrap v2.3.2 CSS file, the CSS is as follows for your snippet:

        .nav-tabs > li.active > a,
        .nav-tabs > li.active > a:hover,
        .nav-tabs > li.active > a:focus {
          color: #555555;
          cursor: default;
          background-color: #ffffff;
          border: 1px solid #dddddd;
          border-bottom-color: transparent;
          } 

Compare this to your CSS snippet as you can see, you are missing the li selector before .active selector. Your CSS is correct however it does not work as the specificity in the Bootstrap CSS is more. So Just change your code snippet to by increasing specificity:

        .nav-tabs > li.active > a,
        .nav-tabs > li.active > a:hover,
        .nav-tabs > li.active > a:focus{
            color: #555555;
            background-color: red;  
        } 

Now your browser when it renders the page will choose your CSS snippet. You can see an example here: http://jsfiddle.net/yyPrg/

You can read up on CSS specificity here: http://css-tricks.com/specifics-on-css-specificity/ and here: http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/

like image 90
Gloria Avatar answered Sep 22 '22 05:09

Gloria