How to change active link color in bootstrap css?
Finally with experiments I found how to capture it.
#top-menu .current a
{
color: orange !important;
}
Thank you everyone for your time and help.
Much appreciated!
Bootstrap 4 navbar active backgroup color
Bootstrap 4 doesn't have css for active class.
So you have to add css by your self
Simply add css like
.active {
background:#4FA9DC; color:#000;
}
Change link color (when active) with jQuery
I found a solution that is working exactly like I wanted to so I wanted to share it ! :)
jQuery(function($) {
var path = window.location.href;
$('li a').each(function() {
if (this.href === path) {
$(this).addClass('active');
}
});
});
Bootstrap 4 navbar active class
There are multiple issues...
- The selector $('.nav li') does nothing because you have no
.nav
class used anywhere in the markup. It should be $('.navbar-nav .nav-link'). - You have
style="color:white"
on the links which will override any changes you make with theactive
class. - You have no CSS for the active class, and by default Bootstrap active class on navbar-dark is going to be white. What color are you trying to set?
- Set active in the
nav-link
instead of the li,
.navbar-dark .nav-item > .nav-link.active {
color:white;
}
$('.navbar-nav .nav-link').click(function(){
$('.navbar-nav .nav-link').removeClass('active');
$(this).addClass('active');
})
Demo: https://www.codeply.com/go/I3EjDb74My
bootstrap4 navbar set active link
Bootstrap documentation says:
Active states—with .active—to indicate the current page can be applied
directly to .nav-links or their immediate parent .nav-items.
So you need to place active
class on nav-item
to make it work. Like this:
<nav class="navbar navbar-expand-sm"> <button class="navbar-toggler" type="button" data-target="#navigation"> <span class="navbar-toggler-icon"></span> </button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active"> <a href="{% url 'terminal-management' %}" class="nav-link"> Terminals </a> </li>
<li class="nav-item"> <a href="{% url 'location-management' %}" class="nav-link active"> Area & Rooms </a> </li>
</ul>
</div>
</nav>
Probably you won't need to define a custom style to it, but you can using this css selector:
.nav-link.active {
color: red;
}
Related Topics
Image-Less Pure-CSS Arrow Tags
Why Am I Unable to Apply a Border to an Angular Mat-Table Row
The Fieldset's Background Color Gets Out of Border in Ie
Phonegap: Inappbrowser Insertcss File
Fixed Vertical Positioning of CSS Within an Iframe
How to Enhance by CSS an HTML <Select> and Its <Option> on Ie 6
Text Is Wrapping Under Bullet in CSS List
Codemirror Cursor Position Offset
How to Disable Mat-Tab Animations with Pure CSS
Li: Before Content: "✔ "; Different Color on Some Mobile Devices
Chrome Not Picking Up @Font-Face Otf
Horizontally Center <P> Within a Div While Keeping The Text Left-Aligned
Nested Div with Margin Top Set Causes Scrollbar to Appear
CSS Selector to Check That Attribute Does Not Contain Both Values
Blue Border Around Image Maps in Internet Explorer 9