A current project involves working on a sidebar created in bootstrap, and I've encountered an issue. I can't seem to move a selected item to the right and have it flow over the nav div. I attempted to increase the z-index with no success.
One suggestion I've considered is utilizing flexbox instead. By adding a cell in front and next to the menu item, I could set the width on the first cell when an item is selected and set a width of 0 to the last cell. The other (unselected) items could have a width set on the last cell. This could potentially achieve the desired visual effect.
Any advice or alternative suggestions are greatly appreciated.
HTML:
<nav class="col-sm-3 col-md-2 d-none d-sm-block bg-faded sidebar vdl-sidebar">
<ul class="nav nav-pills flex-column">
<li class="nav-item" ng-reflect-klass="nav-item">
<a class="nav-link d-flex justify-content-between align-items-center" href="#">
Item 11
<span class="badge badge-pill pull-right badge-success">on</span>
</a>
</li>
<li class="nav-item selected">
<a class="nav-link d-flex justify-content-between align-items-center">
Item 13
<span class="badge badge-pill pull-right badge-success">on</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link d-flex justify-content-between align-items-center" href="#">
Item 14
<span class="badge badge-pill pull-right badge-success">on</span>
</a>
</li>
</ul>
</nav>
CSS:
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 51px;
bottom: 0;
left: 0;
z-index: 1000;
padding: 20px;
overflow-x: hidden;
overflow-y: hidden;
/* Scrollable contents if viewport is shorter than content. */
border-right: 1px solid #eee;
}
/* Sidebar navigation */
.sidebar {
padding-left: 0;
padding-right: 0;
}
.sidebar .nav {
margin-bottom: 20px;
}
.sidebar .nav-item {
width: 100%;
background-color: #f9f9f9;
border-bottom: 1px solid white;
border-top: 1px solid white;
}
@media (pointer: fine) {
nav.vdl-sidebar a.nav-link:hover {
background-color: lightgreen;
}
}
.sidebar .nav-item+.nav-item {
margin-left: 0;
}
.sidebar .nav-item+.nav-item.selected {
margin-left: 20px;
z-index: 2000;
}
.sidebar .nav-link {
border-radius: 0;
}
nav.vdl-sidebar a.nav-link.active {
background-color: green;
}
nav.vdl-sidebar a.nav-link:not(.active) {
color: green;
}
.badge-pill {
padding-bottom: 0.5em;
}
a {
cursor: pointer;
}
.selected {
margin-left: 1.5em;
background-color: lightgreen;
}
Screenshot:
https://i.sstatic.net/JflqX.png
My fiddle link for further reference: https://jsfiddle.net/09ogyde4/