简体   繁体   中英

ASP.Net MVC Controlling the tab bar

I create a new asp.net MVC project and began modifying it to my needs. I am having a problem controlling the colors of the tab bar. I added these changes to the site.css file

 .navbar-inverse 
{ background-color: lightblue !important;


}
.nav.navbar-nav li a {
   color: black !important;
   font-weight: bold !important;

 }

The first section changed the background color like I wanted. The second part changed the text color except for the first tab, the one that comes before the home tab. Also for the tabs that did change I lost the hover color. They used to turn white when I hovered over them. That only works now for the first tab.

I want to change the color of the first tab and also restore the hover color change for all tabs.

See attached image.

标签栏

The problem is that you are using the !important flag.

I recommend that you create your own custom class, something like .navbar-custom .

Change:

<nav class="navbar navbar-inverse">

To:

<nav class="navbar navbar-custom">

Here's an example to point you in the right direction:

 /*Navbar styles*/ .navbar-custom { background-color: lightblue; } /*Navbar brand styles*/ .navbar-custom .navbar-brand { color: black; } /*Navbar brand hover styles*/ .navbar-custom .navbar-brand:hover, .navbar-custom .navbar-brand:focus { color: blue; } /*Navbar anchor styles*/ .navbar-custom .nav.navbar-nav li a { color: black; font-weight: bold; } /*Navbar anchor hover styles*/ .navbar-custom .nav>li>a:focus, .navbar-custom .nav>li>a:hover { background-color: #eee; } /* Mobile navbar toggle styles*/ .navbar-custom .navbar-toggle { border-color: #333; } .navbar-custom .navbar-toggle .icon-bar { background-color: #333; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <nav class="navbar navbar-custom"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Brand</a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a> </li> <li><a href="#">Link</a> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a> </li> <li><a href="#">Another action</a> </li> <li><a href="#">Something else here</a> </li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a> </li> <li role="separator" class="divider"></li> <li><a href="#">One more separated link</a> </li> </ul> </li> </ul> <form class="navbar-form navbar-left"> <div class="form-group"> <input type="text" class="form-control" placeholder="Search"> </div> <button type="submit" class="btn btn-default">Submit</button> </form> <ul class="nav navbar-nav navbar-right"> <li><a href="#">Link</a> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a> </li> <li><a href="#">Another action</a> </li> <li><a href="#">Something else here</a> </li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a> </li> </ul> </li> </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container-fluid --> </nav> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM