How to create smooth transition on nav - html

I have a working navigation, but I want the transition between switching dropdown menus to be smoother. Right now, there is an uncomfortable 'blinking' when you hover between the various main menu links. I know it is caused because of the transition time, but I'm not sure how to fix it. I want the transition to be seamless, as if only the dropdown items themselves are changing (not the background).
Below is my code, and here is a link to a CodePen (https://codepen.io/zp12345/pen/mQzvXr). Any help is appreciated. Thanks!
HTML
<div class="nav-links">
<ul class="nav-primary" id="nav-primary">
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item One</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Two</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Three</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Four</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>4.1</h5>
</a>
</li>
</ul>
</li>
</ul>
</div>
SCSS
.nav-primary {
display: flex;
flex-grow: 1;
justify-content: center;
list-style-type: none;
padding-left: 0;
}
.nav-item-top .nav-item-label {
color: #383838;
font-size: 18px;
padding: 0 24px;
cursor: pointer;
}
.nav-item-top {
&:hover {
.nav-item-label {
color: #319644;
}
.nav-dropdown {
visibility: visible;
opacity: 1;
padding: 16px 0;
}
}
}
.nav-dropdown {
width: 100%;
left: 0;
position: fixed;
top: 60px;
transition: .2s;
opacity: 0;
z-index: 3;
padding: 0;
background-color: #133751;
color: #133751;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
list-style-type: none;
.nav-dropdown-item {
transition: .2s;
padding: 12px 24px;
text-align: center;
color: #fff;
cursor: pointer!important;
}
h5 {
color: #fff;
margin: 0;
text-transform: none;
font-size: 16px;
}
}
.nav-dropdown-item {
a {
transition: all 0.2s;
text-decoration: none;
}
}

In your styles you can adjust the .nav-dropdown transition property to a higher time to make it seem more smooth.
.nav-dropdown {
transition: 2s;
}

As mentioned by #mike-tung, it is about timing of the transition.
You could use an opacity effect on nav-dropdown with low transition timing. It would run smoothly.
.nav-hover:hover {
.nav-dropdown {
transition: 0.3s ease;
opacity: 1;
}
}
.nav-dropdown {
transition: 0.2s ease;
opacity: 0;
...
}
And I see an issue that when you hover out the nav bar, the dropdown is immediately hidden, making it virtually impossible for user to access it.
Thus, I'd suggest you to reduce the top attribute ov nav-dropdown, so it stays right below the NAV menu, and then set the background color only to your .nav-dropdown-item.
.nav-dropdown-item {
width: 100%;
background-color: #133751;
...
}
And giving a padding top to .nav-dropdown:
padding: 20px 0 0; // I let the 0s to not mess with your original padding: 0;
The results would be something like this:
https://codepen.io/annabranco/pen/QJYWvm?editors=1100
Hope it helps! :)

Related

How to adjust animation linked to a hover event?

I have a header composed of navigation links to other websites, some of these links are shown through drop-down menus. With the event hover I have added an animation and style to see what you are on at every moment and that, in case of a drop-down, shows you all the options. The thing is that once the dropdown has been shown I have added the same style and animation to the internal links as to the main ones, but in the case of the animation I always have the underline in the same place instead of just below each link. Thanks in advance for your time and help. I leave you a link with an example as I have it now working with the described behavior
https://codepen.io/carlosurra/pen/YzqXjdP
my template
<div id="row">
<div class="col-xs-12">
<header>
<nav class="navbar navbar-expand-lg navbar-light header">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav menu">
<li class="nav-item">
<a class="nav-link">PERSONAL INFO</a>
</li>
<li class="nav-item" #mouseover="animalList = true" #mouseleave="animalList = false" >
<a class="nav-link menu-link-toggle" >PERSONAL FORM</a>
<ul class='dropdown-menu' v-if="animalList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>FORM DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >AUTOCOMPLETE</a>
</li>
</ul>
</li>
<li class="nav-item" #mouseover="serviceList = true" #mouseleave="serviceList = false">
<a class='nav-link menu-link menu-link-toggle' >SERVICES</a>
<ul class='dropdown-menu' v-if="serviceList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >LA CRÉMATION PRIVÉE</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PERSONAL S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>COMPANY S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >FULL S INFO</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link ">SHOP</a>
</li>
<li class="nav-item active">
<router-link class="nav-link" to="/devis">PRICES</router-link>
</li>
<li class="nav-item" #mouseover="contactList = true" #mouseleave="contactList = false">
<a class='menu-link nav-link menu-link-toggle' >CONTACT</a>
<ul class='dropdown-menu' v-if="contactList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>MAIL</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PHONE</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</header>
</div>
</div>
my css
html, body {
background: #009050;
}
.header {
display: flex;
justify-content: center;
align-items: baseline;
}
.menu {
list-style: none;
display: flex;
align-items: center;
}
.nav-item {
padding: 25px;
position: relative;
}
.nav-link:hover {
color: white;
}
.menu-link-toggle {
cursor: pointer;
}
.dropdown-menu {
margin-top: 10px;
list-style: none;
position: absolute;
padding: 1em 1.25em 0.5em 0.75em;
background-color: white;
width: max-content;
box-shadow: 0px 14px 24px 0px rgba(0,0,0,0.21);
}
.dropdown-menu-item {
margin: 20px 0 20px 0;
}
.dropdown-menu-link {
font-size: 14px;
font-weight: bold;
color: red;
text-decoration: none;
}
.head {
font-size: 14px;
color: red;
font-weight: bold;
text-decoration: none;
}
.nav-item:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 35%;
background: white;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.nav-item:hover:before,
.nav-item:focus:before {
visibility: visible;
transform: scaleX(1);
}
.dropdown-menu-link:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 0%;
background: #D53865;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.dropdown-menu-link:hover:before,
.dropdown-menu-link:focus:before {
visibility: visible;
transform: scaleX(1);
}
.added {
display: none;
}
Please add this to your code
.dropdown-menu-link {
padding-bottom:3px;
position:relative;
}
.dropdown-menu-item {
position:relative;
}
Change the code bottom:30%; to bottom: 0px;
.dropdown-menu-link:before {
bottom: 0px;
}
Please check this codepen :
https://codepen.io/Rayeesac/pen/LYNpyEx
Add position: relative to .dropdown-menu-item and set a correct position to bottom of .dropdown-menu-item:before, let's say to 0px;
Or if you want to be relative to the link set position: relative to .dropdown-menu-link.

Transition effect creating a bug

I am working on a horizontal dropdown navigation menu. I am using a transition to slow it down, but I've hit a bug. If you jump too fast (before the transition completes?) from one nav item to the other, you are still shown the other dropdown menu. It's a bit hard to explain - but I've created a CodePen.
I'm sure I'm just overlooking something basic... all feedback is appreciated. Thank you in advance!
CodePen link: https://codepen.io/zp12345/pen/mQzvXr
HTML
<div class="nav-links">
<ul class="nav-primary" id="nav-primary">
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item One</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Two</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Three</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Four</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>4.1</h5>
</a>
</li>
</ul>
</li>
</ul>
</div>
SCSS
.nav-primary {
display: flex;
flex-grow: 1;
justify-content: center;
list-style-type: none;
padding-left: 0;
}
.nav-item-top .nav-item-label {
color: #383838;
font-size: 18px;
padding: 0 24px;
cursor: pointer;
}
.nav-item-top {
&:hover {
.nav-item-label {
color: #319644;
}
.nav-dropdown {
visibility: visible;
opacity: 1;
padding: 16px 0;
}
}
}
.nav-dropdown {
width: 100%;
left: 0;
position: fixed;
top: 60px;
transition: .2s;
opacity: 0;
z-index: 3;
padding: 0;
background-color: #133751;
color: #133751;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
list-style-type: none;
.nav-dropdown-item {
transition: .2s;
padding: 12px 24px;
text-align: center;
color: #fff;
cursor: pointer!important;
}
h5 {
color: #fff;
margin: 0;
text-transform: none;
font-size: 16px;
}
}
.nav-dropdown-item {
a {
transition: all 0.2s;
text-decoration: none;
}
}
You can use transition-delay:0.2s; on hover when you show the .nav-dropdown. That will not show the dropdown when you move mouse fast.
You can test it here

How to stop the jittering on the circles when hovering

I have created a basic menu with years on the top and a circle below. When hovering over the li the font size is increased but this seems to be causing a wobble or jitter on the circle below.
How do I stop this and have smooth effect on hover? I have included my css and html in a code snippet so you can see what I am talking about.
#timeline ul {
text-align: center;
text-transform: uppercase;
margin: 0;
padding: 0;
}
ul li {
position: relative;
display: inline-block;
float: none;
width: 5%;
max-width: 140px;
padding: 25px 0;
transition: all .3s ease;
box-sizing: border-box;
text-align: center;
font-family: alternate-gothic-no-3-d,Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 20px;
}
#timeline ul .hovered, #timeline ul li:hover {
transition: all .5s;
font-size: 35px;
cursor: pointer;
padding-top: 12px;
padding-bottom: 21px;
}
#timeline ul li .indicator {
display: block;
}
#timeline ul li .title:before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
width: 12px;
height: 12px;
border: 3px solid #a39688;
border-radius: 100%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
transition: all .3s ease;
}
<div id="timeline">
<ul class="timeline-list">
<li class="" data-number="1">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="2">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="hovered" data-number="3">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="4">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="5">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="6">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="7">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="8">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="9">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="10">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="11">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
</ul>
</div>
Try to made the .title absolute as i did in the code
#timeline ul {
text-align: center;
text-transform: uppercase;
margin: 0;
padding: 0;
}
span.title {
position: absolute;
width: 100%;
text-align: center;
left: 0;
bottom: 20px;
}
ul li {
position: relative;
display: inline-block;
float: none;
width: 5%;
max-width: 140px;
padding: 25px 0;
transition: all .3s ease;
box-sizing: border-box;
text-align: center;
font-family: alternate-gothic-no-3-d,Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 20px;
height: 80px;
}
#timeline ul .hovered, #timeline ul li:hover {
transition: all .5s;
font-size: 35px;
cursor: pointer;
padding-top: 12px;
padding-bottom: 21px;
}
#timeline ul li .indicator {
display: block;
}
#timeline ul li:before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
width: 12px;
height: 12px;
border: 3px solid #a39688;
border-radius: 100%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
transition: all .3s ease;
}
<div id="timeline">
<ul class="timeline-list">
<li class="" data-number="1">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="2">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="hovered" data-number="3">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="4">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="5">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="6">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="7">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="8">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="9">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="10">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="11">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
</ul>
</div>
You have a few problems:
inline blocks don't like whitespace between them
add vertical-align: top; to the css of ul li
the main problem is you're trying to substitute font-size for padding. In the normal li it is 25px padding + 20px font + 25px padding, in the hover it is 12px padding + 35px font.
the solution: remove all the padding, and only add line-height: 75px to the css of ul li
Here's a working fiddle

CSS Vertical Nav Issue with Z-Index and Drop Down List

#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>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link</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</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</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>
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:
<li class="nav-item">
<span class="before-bar"></span>
<a class="nav-link active" href="#"><i class="fa fa-fw fa-home"></i> Home</a>
</li>
.before-bar {
position: absolute;
height: 100%;
width: 3px;
}
.sidebar-nav li:nth-child(2):before,
.sidebar-nav li:nth-child(2) .before-bar {
background-color: #d12525;
}
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).
To keep the text on top, change the z-index for li:before
.sidebar-nav li:before {
content: '';
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width 0.2s ease-in;
width: 3px;
z-index: -1;
}
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.
.sidebar-nav li a{
position:relative;
z-index:0;
}
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.
Try to add bootstrape.min.js

Position font awesome span icon above text within an anchor

I'm trying to make some buttons with text positioned below a font awesome icon where both are positioned centrally inside a list item, and I need the anchor element, which also contains the span element for the font awesome icon, to fill the entire size of the list item.
I can fill the list item with the anchor no problem, but I'm having trouble positioning the icon's span above the text in the anchor that contains it.
JSFiddle: https://jsfiddle.net/qod142fz/.
HTML:
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><span class="fa fa-home"></span>Home</li>
<li class="navButton"><span class="fa fa-user"></span>Personal Details</li>
<li class="navButton"><span class="fa fa-briefcase"></span>Company</li>
<li class="navButton"><span class="fa fa-gbp"></span>Invoices</li>
<li class="navButton"><span class="fa fa-address-book"></span>Contacts</li>
<li class="navButton"><span class="fa fa-minus"></span>Expenses</li>
<li class="navButton"><span class="fa fa-list"></span>Payslips</li>
<li class="navButton"><span class="fa fa-cog"></span>Settings</li>
</ul>
</div>
CSS:
/* SIDEBAR PRIMARY */
#sidebarPrimary
{
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary > ul
{
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary > ul > li.navButton
{
width: 100%;
height: 15vw;
}
#sidebarPrimary > ul > li.navButton > a
{
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary > ul > li.navButton > a:hover
{
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary > ul > li.navButton > a > span
{
display: block;
text-align: center;
margin-bottom: 5px;
}
Problem is coming from flex. I recommend wrapping another div around the elements that should be centered inside the a tags
/* SIDEBAR PRIMARY */
#sidebarPrimary {
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary > ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary > ul > li.navButton {
width: 100%;
height: 15vw;
}
#sidebarPrimary > ul > li.navButton > a {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
text-decoration: none;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary > ul > li.navButton > a:hover {
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary > ul > li.navButton > a .fa {
display: block;
height: 1em;
margin: 0 auto 5px;
text-align: center;
width: 1em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-home"></span>Home
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-user"></span>Personal Details
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-briefcase"></span>Company
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-gbp"></span>Invoices
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-address-book"></span>Contacts
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-minus"></span>Expenses
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-list"></span>Payslips
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-cog"></span>Settings
</div>
</a></li>
</ul>
</div>
#sidebarPrimary {
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary>ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary>ul>li.navButton {
width: 100%;
height: 15vw;
}
#sidebarPrimary>ul>li.navButton>a {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary>ul>li.navButton>a:hover {
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary>ul>li.navButton>a>span {
display: block;
text-align: center;
margin-bottom: 5px;
width: 20px;
height: 20px;
background-color: red;
position: absolute;
top: 10px;
}
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><span class="fa fa-home"></span>Home</li>
<li class="navButton"><span class="fa fa-user"></span>Personal Details</li>
<li class="navButton"><span class="fa fa-briefcase"></span>Company</li>
<li class="navButton"><span class="fa fa-gbp"></span>Invoices</li>
<li class="navButton"><span class="fa fa-address-book"></span>Contacts</li>
<li class="navButton"><span class="fa fa-minus"></span>Expenses</li>
<li class="navButton"><span class="fa fa-list"></span>Payslips</li>
<li class="navButton"><span class="fa fa-cog"></span>Settings</li>
</ul>
</div>
Just add position: absolute; top: 40px; to font-awesome icons