So for some reason, my hover CSS is not working. I am using bootstrap with some of their css. Is there something wrong with my code, or is it because bootstrap's code is overriding mine's?
HTML
<nav class="navbar navbar-default navbar-fixed-top">
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav" role="tablist">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">About</a></li>
</ul>
</div>
</nav>
CSS
ul>li>a {
color: black;
padding: 15px;
}
ul>li>a:hover {
background-color: #B0B0B0;
color: red;
}
It's because the default Bootstrap styling is more specific. Save this answer. Show activity on this post. Without seeing exactly whats going on, the issue you're having may be related to not specifying a class on your unordered list.
Wrong CSS Format Also, if you incorrectly write a selector and wish to apply a hover effect on it, you will notice that the styling does not work as expected in any browser. To solve the issue, you need to go over the CSS hover code to establish if you use the right selector.
Definition and Usage The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links.
It's because the default Bootstrap styling is more specific.
These are the selectors that you need to override:
.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav>li>a:focus {
color: #333;
background-color: transparent;
}
Therefore you could use:
Working Example Here
.navbar-default .navbar-nav>li>a:hover {
background-color: #B0B0B0;
color: red;
}
Without seeing exactly whats going on, the issue you're having may be related to not specifying a class on your unordered list.
This may fix the problem:
ul.navbar-nav > li > a {
color:black;
padding: 15px;
}
ul.navbar-nav > li > a:hover {
background-color: #B0B0B0;
color:red;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With