New to Bootstrap here. I've been trying for a few hours now. Maybe there is something simple I am missing.
Basically, I'm trying to keep nav-link active when browsing in a sub-directory.
When I click on "Accounts" (site.com/accounts
) it correctly marks nav-link
as active
.
Accounts
is a list of accounts.
When I click on one of the accounts from the list we should go to the account (site.com/accounts/0000734174
) but the Accounts nav-link in the sidebar is no longer active.
How do I keep it active while keeping the href "/accounts", because in my mind it should be. There are thousands of accounts and we wouldn't want a drop-down child nav-link for each.
Do I have the concept wrong? please help. Thanks
edit: let me add this is routed with code igniter as:
$route[ 'accounts/(:num)' ] = "accounts_details";
$route[ 'accounts' ] = "accounts_list";
And let me add what I've tried. different Jquery snippets found here on SO, different CSS failures, different routing ideas. And also this is in CoreUI Template using CodeIgniter framework.
More details: HTML-
<div class="sidebar">
<nav class="sidebar-nav">
<ul class="nav">
<li class="nav-title">Navigation</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url(); ?>accounts">
<i class="nav-icon icon-folder-alt"></i> Accounts</a>
</li>
</ul>
</nav>
</div>
CSS-
.sidebar .nav-link.active {
color: #fff;
background: #3a4248;
}