@import "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
@import "https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css";
@import "https://daneden.github.io/animate.css/animate.min.css";
@media (min-width: 768px) {
.bootstrap-vertical-nav .collapse {
display: block;
}
}
/*-------------------------------*/
/* Sidebar nav styles */
/*-------------------------------*/
.sidebar-nav {
list-style: none;
margin: 0;
padding: 0;
position: absolute;
top: 0;
width: 220px;
}
.sidebar-nav li {
display: inline-block;
line-height: 20px;
position: relative;
width: 100%;
}
/* this background color doesn't trigger */
.sidebar-nav li:before {
content: '';
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width 0.2s ease-in;
width: 3px;
z-index: 0;
}
.sidebar-nav li:first-child a {
background-color: #1a1a1a;
color: 555;
}
.sidebar-nav li:nth-child(2):before {
background-color: #d12525;
}
.sidebar-nav li:nth-child(3):before {
background-color: #4c366d;
}
.sidebar-nav li:nth-child(4):before {
background-color: #583e7e;
}
.sidebar-nav li:nth-child(5):before {
background-color: #64468f;
}
.sidebar-nav li:nth-child(6):before {
background-color: #704fa0;
}
.sidebar-nav li:nth-child(7):before {
background-color: #7c5aae;
}
.sidebar-nav li:nth-child(8):before {
background-color: #8a6cb6;
}
.sidebar-nav li:nth-child(9):before {
background-color: #987dbf;
}
.sidebar-nav li:hover:before {
transition: width 0.2s ease-in;
width: 100%;
}
.sidebar-nav li a {
background-color: #1a1a1a;
color: #fff;
display: block;
padding: 10px 15px 10px 30px;
text-decoration: none;
z-index: -2;
}
.sidebar-nav li.open:hover before {
transition: width 0.2s ease-in;
width: 100%;
}
.sidebar-nav .dropdown-menu {
background-color: #222222;
border-radius: 0;
border: none;
box-shadow: none;
margin: 0;
padding: 0;
position: relative;
width: 100%;
}
.sidebar-nav li a:hover,
.sidebar-nav li a:active,
.sidebar-nav li a:focus,
.sidebar-nav li.open a:hover,
.sidebar-nav li.open a:active,
.sidebar-nav li.open a:focus {
background-color: transparent;
color: #fff;
text-decoration: none;
}
.sidebar-nav > .sidebar-brand {
font-size: 20px;
height: 65px;
line-height: 44px;
}
<div class="collapse" id="collapseExample">
<ul class="nav flex-column sidebar-nav" id="exCollapsingNavbar3">
<li class="nav-item sidebar-brand">
<a nav-link href="#">
Bootstrap 4
</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#"><i class="fa fa-fw fa-home"></i> Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-fw fa-folder"></i> Page one</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-fw fa-file-o"></i> Second page</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-fw fa-cog"></i> Third page</a>
</li>
<li class="nav-item dropdown">
<a class="nav-item" href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-fw fa-plus"></i> Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Dropdown heading</li>
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-fw fa-bank"></i> Page four</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-fw fa-bank"></i> Page 5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-fw fa-twitter"></i> Last page</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
Issue 1) I’m working on a HTML + CSS sidenav, I’m having some trouble with the Z-Index, if you hover over an item in the side nav, there will be a color transition from left to right. I want the text to stay on top.
Issue 2) My drop down list won’t work at all, I thought i followed the bootstrap tutorial on it.
This entire project is an angular2 project. if you can use ng-bootstrap for any of the functionality, great! if not, i appreciate any feedback on how to resolve either issue.
UPDATED: Solution, you’ll need ng-bootstrap to have it working. Wasn’t sure how to add the library to the snippet tool.
@import "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css";
@import "https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css";
@import "https://daneden.github.io/animate.css/animate.min.css";
@media (min-width: 768px) {
.bootstrap-vertical-nav .collapse {
display: block;
}
}
/*-------------------------------*/
/* Sidebar nav styles */
/*-------------------------------*/
.sidebar-nav {
list-style: none;
margin: 0;
padding: 0;
position: absolute;
top: 0;
width: 220px;
}
.sidebar-nav li {
display: inline-block;
line-height: 20px;
position: relative;
width: 100%;
}
.sidebar-nav div {
display: inline-block;
line-height: 20px;
position: relative;
width: 100%;
}
/* this background color doesn't trigger */
.sidebar-nav li:before {
content: '';
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width 0.2s ease-in;
width: 3px;
z-index: -2;
}
.sidebar-nav div:before {
content: '';
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width 0.2s ease-in;
width: 3px;
z-index: -2;
}
.sidebar-nav li:first-child a {
background-color: #1a1a1a;
color: 555;
}
.sidebar-nav li:nth-child(n):before {
z-index: 1;
background-color: #b7e7ff;
}
.sidebar-nav li:nth-child(1):before {
background-color: transparent;
}
/*
BLUE: 0085c6 and darker is: 0c78ad
YELLOW: f3c300
BLACK: 000
GREEN: 009f3d
RED: e00024
*/
.sidebar-nav li:nth-child(n) div:before {
background-color: #0085c6;
z-index: 1;
}
.sidebar-nav li:hover:before {
transition: width 0.2s ease-in;
width: 100%;
z-index: -1;
}
.sidebar-nav li a {
background-color: #1a1a1a;
color: #fff;
display: block;
padding: 10px 15px 10px 30px;
text-decoration: none;
}
.sidebar-nav li.open:hover before {
transition: width 0.2s ease-in;
width: 100%;
}
.sidebar-nav .dropdown-menu {
background-color: #1a1a1a;
border-radius: 0;
border: none;
box-shadow: none;
margin: 0;
padding: 0 0 0 15%;
position: relative;
width: 100%;
}
.sidebar-nav .dropdown-menu li:nth-child(1):before {
background-color: #b7e7ff;
}
.sidebar-nav li a:hover,
.sidebar-nav li a:active,
.sidebar-nav li a:focus,
.sidebar-nav li.open a:hover,
.sidebar-nav li.open a:active,
.sidebar-nav li.open a:focus {
background-color: transparent;
color: #fff;
text-decoration: none;
}
.sidebar-nav>.sidebar-brand {
font-size: 20px;
height: 65px;
line-height: 44px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-4 col-lg-3">
<!--<div id="collapseExample" [ngbCollapse]="isCollapsed">
<div class="card">
<div class="card-block">
You can collapse this card by clicking Toggle
</div>
</div>
</div>-->
<div id="collapseExample" [ngbCollapse]="isCollapsed" class="bootstrap-vertical-nav">
<div class="collapse" id="collapseExample">
<ul class="nav flex-column sidebar-nav" id="exCollapsingNavbar3">
<li class="nav-item sidebar-brand">
<a nav-link href="#">
Bootstrap 4
</a>
</li>
<li class="nav-item">
<div>
<a class="nav-link active" href="#"><i class="fa fa-fw fa-home"></i> Home</a>
</div>
</li>
<li class="nav-item">
<div>
<a class="nav-link" href="#"><i class="fa fa-fw fa-folder"></i> Page one</a>
</div>
</li>
<li class="nav-item">
<div>
<a class="nav-link" href="#"><i class="fa fa-fw fa-file-o"></i> Second page</a>
</div>
</li>
<li class="nav-item">
<div>
<a class="nav-link" href="#"><i class="fa fa-fw fa-cog"></i> Third page</a>
</div>
</li>
<li class="nav-item dropdown">
<div ngbDropdown>
<a class="nav-item" href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-fw fa-plus"></i> Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">a</a></li>
<li><a href="#">b</a></li>
<li><a href="#">c</a></li>
<li><a href="#">d</a></li>
<li><a href="#">e</a></li>
</ul>
</div>
</li>
<li class="nav-item">
<div>
<a class="nav-link disabled" href="#">Disabled</a>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="col-md-8 col-lg-9">
<p>
<button type="button" class="btn btn-outline-primary" (click)="isCollapsed = !isCollapsed" [attr.aria-expanded]="!isCollapsed" aria-controls="collapseExample">
Toggle
</button>
</p>
<hr />
<div>
<h1>Right Pane - Bootstrap 4.0 Vertical Nav Example</h1>
</div>
</div>
</div>
</div>
3
Answers
To keep the text on top, change the z-index for li:before
Issue 1) I’m working on a HTML + CSS sidenav, I’m having some trouble with the Z-Index, if you hover over an item in the side nav, there will be a color transition from left to right. I want the text to stay on top.
Issue 2) My drop down list won’t work at all, I thought i followed the bootstrap tutorial on it.
This entire project is an angular2 project. if you can use ng-bootstrap for any of the functionality, great! if not, i appreciate any feedback on how to resolve either issue.
The problem is you cannot use that li:before for both showing the left colored bar and also for the color transition, and still have the text on top.
What I suggest is adding a span element inside you list item, and that span should represent the colored bar that should always be present:
See http://plnkr.co/edit/AHaTOQmBwllZV5bATFtJ?p=preview (only modified for the “Home” link)
Probably an even better solution would be to keep the li:before for the 3px color bar, and have the span for the color transition (with a lower z-index).