I'm developing a single page HTML5 and CSS3 based theme using Bootstrap 3.
The problem is that I couldn't remove the active link styling (gray background) that Bootstrap adds when I click a link.
It's handy for normal multi-page sites but here the page won't change.
So the gray background will remain until I click anywhere on the page.
My HTML is as follows:
<nav class="navbar navbar-custom navbar-fixed-top sticky-nav" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="#"><img src="_/css/img/logo4.png" alt="" /></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right text-thin">
<li class="active"><a href="#home">Home</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#portfolio">Portfolio</a></li>
<li><a href="#clients">Our Clients</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div> <!-- /.container -->
</nav>
And my CSS is:
.nav > li > a {
background: #fff;
}
.navbar {
margin: 0;
padding: 25px 0;
box-shadow: 0 0px 2px rgba(0, 0, 0, .3);
}
.navbar-custom {
background-color: #fff;
border-radius: 0;
height: 100px;
}
.navbar-custom .navbar-brand img {
width: 90px;
height: 60px;
}
.shrink {
padding: 10px 0;
height: 50px;
}
.navbar-custom .navbar-nav > li > a {
color: #555;
font-size: 18px;
text-transform: uppercase;
margin-left: 5px;
padding: 10px;
}
.navbar-custom .navbar-nav > li > a:hover {
color: #c00;
background-color: #fff;
}
.navbar-custom .navbar-nav > .active > a,
.navbar-nav > .active > a:hover,
.navbar-nav > .active > a:focus {
color: #c00;
}
.navbar-custom .navbar-brand {
color: #eeeeee;
padding: 0;
margin-top: -5px;
}
.shrink .navbar-brand img {
width: 70px;
height: 40px;
}
.shrink .navbar-nav > li > a {
padding-top: 5px;
padding-bottom: 5px;
font-size: 12px;
}
.shrink button {
margin-top: 0;
}
.navbar-custom .icon-bar {
background-color: #555;
}
.active {
background: #fff;
}
How can I achieve that?
Comparing your CSS with that in effect on Bootstrap's Navbar example , it seems that the problem is that your selectors for the :hover
and :focus
cases aren't specific enough, making your rules fail to override Bootstrap's default ones. If you add .navbar-custom
to these two rules I think it should work (provided your CSS is included after the Bootstrap one):
.navbar-custom .navbar-nav > .active > a,
.navbar-custom .navbar-nav > .active > a:hover,
.navbar-custom .navbar-nav > .active > a:focus {
color: #c00;
background-color: #fff;
}
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.