I have a side bar using Bootsrap CSS, but the class=" active" does not work.
Here , the tab Add is not active by default.
Could you please let me know how to make Add active by default when using class="nav nav-sidebar"
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Add </a></li>
<li><a href="#">View/Modify</a></li>
<li><a href="#">Delete</a></li>
</ul>
</div>
Please find below working link: enter link description here
To set an active class in your bootstrap navbar, you can use ng-controller(NavigationController) to set bootstrap navbar active class with AngularJS. To run a single controller outside ng-view. You can set class= “active” when the angular route is clicked.
When you click on a link, it becomes active. Using the:active selector on any element rather than just links makes all elements more active. Use the :link selector to style unvisited links, the :visited selector to style visited links, and the :hover selector to style links when you hover over them.
To display the sidebar on your page select the “Show Sidebar” radio button in the “Hide Sidebar” pane near the bottom right of the editing page (figure 2). Alternatively, select the “Hide Sidebar” radio in order to hide the sidebar and allow content to occupy the full width of the content area.
You have to let it know how you'd like it to look once it's active. And you need a little jquery to do the active swapping for you.
So here I've added the jquery, I've styled li.active (I also styles li a little so I could us the underline example)
Your html is the same though.
$(".nav a").on("click", function() {
$(".nav").find(".active").removeClass("active");
$(this).parent().addClass("active");
});
.nav li {
border-bottom: 3px solid rgba(0, 0, 0, 0);
}
.nav li:hover {
border-bottom: 3px solid #eee;
}
.nav li.active {
border-bottom: 3px solid #338ecf;
background: #eee
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Add </a>
</li>
<li><a href="#">View/Modify</a>
</li>
<li><a href="#">Delete</a>
</li>
</ul>
</div>
I check your code and added some classes. check this out. DEMO here!
HTML:
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar list-group">
<li class="list-group-item active"><a href="#">Add </a></li>
<li class="list-group-item"><a href="#">View/Modify</a></li>
<li class="list-group-item"><a href="#">Delete</a></li>
</ul>
</div>
CSS:
li.list-group-item a:hover {
background-color: transparent;
}
li.list-group-item.active a {
color: #fff;
}
li.list-group-item.active a:hover {
background-color: transparent;
}
.list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover {
background-color: #a8a8a8;
}
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