drop down menu does not push down on hovering over submenu - html

I appologize in advance if this is a silly question. I am trying to make a drop down over menu playing with css, I felt like I was close to success and I mess it all up.
At this point I am drowning in my css style sheet and I cannot find a way to make it work.
Basically, when trying to hover over a menu to get the drop down submenu, the next menu, does not push down to make space to the previous one'submenu, causing them to be both hovering (at least this is how I understand the issue).
I don't seem to find a way to keep the submenu stable when they get hovered over and the next menu to push down
I am hoping someone could point out what I am doing wrong with this css code
nav#sidebar {
width: 280px;
background: #FFFFFF;
color: #6a6c70;
border-right: 1px solid #34373d;
/* shrinked navbar */
}
nav#sidebar a {
color: inherit;
text-decoration: none;
position: relative;
}
nav#sidebar a[data-toggle="collapse"]::after {
content: '\f104';
display: inline-block;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
font-family: 'FontAwesome';
position: absolute;
top: 50%;
right: 20px;
}
nav#sidebar a[aria-expanded="true"] {
background: #FFFFFF;
}
nav#sidebar a[aria-expanded="true"]::after {
content: '\f107';
}
nav#sidebar a i {
font-size: 1.2em;
margin-right: 10px;
-webkit-transition: none;
transition: none;
}
nav#sidebar .sidebar-header {
padding: 30px 20px;
}
nav#sidebar .sidebar-header h1,
nav#sidebar .sidebar-header p {
margin-bottom: 0;
}
nav#sidebar .sidebar-header h1 {
color: #8a8d93;
}
nav#sidebar .sidebar-header p {
font-size: 0.9rem;
}
nav#sidebar span.heading {
font-weight: 700;
margin-left: 20px;
color: #494d53;
font-size: 1.2rem;
margin-bottom: 15px;
}
nav#sidebar .avatar {
width: 60px;
height: 60px;
border-radius: 50%;
overflow: hidden;
margin-right: 15px;
background: none;
padding: 4px;
border: 3px solid #282b2f;
}
nav#sidebar ul {
max-height: none;
}
nav#sidebar li {
position: relative;
/* menu item */
/* submenu item */
/* menu item active */
/* submenu item active */
}
nav#sidebar li a {
padding: 18px 20px;
display: block;
font-weight: 400;
}
nav#sidebar li a:hover {
background: #B5B0B8;
padding-bottom: 15px;
position: relative;
}
nav#sidebar li a:hover i {
color: #060808;
display: block;
position: absolute;
}
nav#sidebar li a i {
margin-right: 20px;
-webkit-transition: all 0.3s;
transition: all 0.3s;
padding-right: 20px;
border-right: 1px solid #454649;
}
nav#sidebar li li a {
padding: 14px;
padding-left: 60px;
background: #FFFFFF;
}
nav#sidebar li li a:hover {
background: #B5B0B8;
display: block;
position: absolute;
min-width: 80px;
padding-bottom: 20px;
}
nav#sidebar li li a:hover i {
color: #060808;
}
nav#sidebar li::before {
content: '';
width: 2px;
height: 100%;
background: none;
display: none;
position: relative;
top: 0;
left: 0;
z-index: 99;
}
nav#sidebar li.active::before {
background: #060808;
}
nav#sidebar li.active > a {
background: #e93030e8;
color: #060808;
}
nav#sidebar li.active i {
color: #060808;
}
nav#sidebar li li.active > a {
background: #FFFFFF;
}
<nav id="sidebar">
<!-- Sidebar Header-->
<div class="sidebar-header d-flex align-items-center">
<div class="title">
<h1 class="h5">Analyse de Stock</h1>
<p>Bienvenue</p>
</div>
</div>
<!-- Sidebar Navigation Menus--><span class="heading">Menu</span>
<ul class="list-unstyled components">
<li class="active">
<a href="#homeSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle collapsed">
<i class="fas fa-home"></i>
Home
</a>
<ul class="list-unstyled collapse" id="homeSubmenu" style="">
<li>
Home Dashboard
</li>
</ul>
</li>
<li>
<a href="#pageSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle collapsed">
<i class="fas fa-copy"></i>
Analytics
</a>
<ul class="list-unstyled collapse" id="pageSubmenu" style="">
<li>
<i class="icon-chart"></i>Sales Analytics
</li>
<li>
<i class="icon-chart"></i>Replenishment Analytics
</li>
<li>
<i class="icon-chart"></i>Items Analytics
</li>
<li>
<i class="icon-chart"></i>Supplier Analytics
</li>
</ul>
</li>
<li>
<a href="#page2Submenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">
<i class="fas fa-copy"></i>
Sales
</a>
<ul class="collapse list-unstyled" id="page2Submenu">
<li>
<i class="icon-padnote"></i>Record Sale
</li>
<li>
<i class="icon-padnote"></i>Sale history
</li>
<li>
<i class="icon-padnote"></i>Search sale
</li>
</ul>
</li>
<li>
<a href="#page3Submenu" data-toggle="collapse" class="dropdown-toggle">
<i class="fas fa-copy"></i>
Orders
</a>
<ul class="collapse list-unstyled" id="page3Submenu">
<li>
<i class="icon-padnote"></i>Record Purchase
</li>
<li>
<i class="icon-padnote"></i>Purchase history
</li>
<li>
<i class="icon-padnote"></i>Search order
</li>
<li>
<i class="icon-padnote"></i>Supplier Replenishment
</li>
<li>
<i class="icon-padnote"></i>Item Replenishment
</li>
</ul>
</li>
<li>
<a href="#page4Submenu" data-toggle="collapse" class="dropdown-toggle">
<i class="fas fa-copy"></i>
Bases
</a>
<ul class="collapse list-unstyled" id="page4Submenu">
<li>
<i class="icon-padnote"></i>Supplier Base
</li>
<li>
<i class="icon-padnote"></i>Item Base
</li>
</ul>
</li>
</ul></nav>

The problem here is really much more about the design and user experience than technical nature. Do you need your submenus to move, fade or anything like that? How does that affect the interaction with the user, who aims the cursor at something? I am afraid, this type of interactive, vertical menu is fundamentally flawed.
Below you can see an example of the code patched up just enough to work, and you can tell the unexpected behavior straight away. In short: a user's action must not change the very context the user is interacting with. In this case the context is the panels the user hovers over. Their positions must not change while the user is aiming.
The problem can be solved in multiple ways:
Static and fully expanded vertical menu
Sub-menu showing up on click and staying expanded (i.e. click to toggle)
Sub-menu being static and visible once the user has navigated to any page within that area (e.g. by clicking on one of the main points)
Horizontal menu
nav#sidebar {
width: 280px;
background: #FFFFFF;
color: #6a6c70;
border-right: 1px solid #34373d;
/* shrinked navbar */
}
nav#sidebar a {
color: inherit;
text-decoration: none;
position: relative;
}
nav#sidebar a[data-toggle="collapse"]::after {
content: '\f104';
display: inline-block;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
font-family: 'FontAwesome';
position: absolute;
top: 50%;
right: 20px;
}
nav#sidebar a[aria-expanded="true"] {
background: #FFFFFF;
}
nav#sidebar a[aria-expanded="true"]::after {
content: '\f107';
}
nav#sidebar a i {
font-size: 1.2em;
margin-right: 10px;
-webkit-transition: none;
transition: none;
}
nav#sidebar .sidebar-header {
padding: 30px 20px;
}
nav#sidebar .sidebar-header h1,
nav#sidebar .sidebar-header p {
margin-bottom: 0;
}
nav#sidebar .sidebar-header h1 {
color: #8a8d93;
}
nav#sidebar .sidebar-header p {
font-size: 0.9rem;
}
nav#sidebar span.heading {
font-weight: 700;
margin-left: 20px;
color: #494d53;
font-size: 1.2rem;
margin-bottom: 15px;
}
nav#sidebar .avatar {
width: 60px;
height: 60px;
border-radius: 50%;
overflow: hidden;
margin-right: 15px;
background: none;
padding: 4px;
border: 3px solid #282b2f;
}
nav#sidebar ul {
max-height: none;
}
nav#sidebar li {
position: relative;
/* menu item */
/* submenu item */
/* menu item active */
/* submenu item active */
}
nav#sidebar li a {
padding: 18px 20px;
display: block;
font-weight: 400;
}
nav#sidebar li li {
overflow: hidden;
display: none;
}
nav#sidebar li:hover li {
height: 100%;
display: block;
}
nav#sidebar li a i {
margin-right: 20px;
-webkit-transition: all 0.3s;
transition: all 0.3s;
padding-right: 20px;
border-right: 1px solid #454649;
}
nav#sidebar li li a {
padding: 14px;
padding-left: 60px;
background: #FFFFFF;
}
nav#sidebar li li a:hover {
background: #B5B0B8;
display: block;
}
nav#sidebar li li a:hover i {
color: #060808;
}
nav#sidebar li::before {
content: '';
width: 2px;
height: 100%;
background: none;
display: none;
position: relative;
top: 0;
left: 0;
z-index: 99;
}
nav#sidebar li.active::before {
background: #060808;
}
nav#sidebar li.active > a {
background: #e93030e8;
color: #060808;
}
nav#sidebar li.active i {
color: #060808;
}
nav#sidebar li li.active > a {
background: #FFFFFF;
}
<nav id="sidebar">
<!-- Sidebar Header-->
<div class="sidebar-header d-flex align-items-center">
<div class="title">
<h1 class="h5">Analyse de Stock</h1>
<p>Bienvenue</p>
</div>
</div>
<!-- Sidebar Navigation Menus--><span class="heading">Menu</span>
<ul class="list-unstyled components">
<li class="active">
<a href="#homeSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle collapsed">
<i class="fas fa-home"></i>
Home
</a>
<ul class="list-unstyled collapse" id="homeSubmenu" style="">
<li>
Home Dashboard
</li>
</ul>
</li>
<li>
<a href="#pageSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle collapsed">
<i class="fas fa-copy"></i>
Analytics
</a>
<ul class="list-unstyled collapse" id="pageSubmenu" style="">
<li>
<i class="icon-chart"></i>Sales Analytics
</li>
<li>
<i class="icon-chart"></i>Replenishment Analytics
</li>
<li>
<i class="icon-chart"></i>Items Analytics
</li>
<li>
<i class="icon-chart"></i>Supplier Analytics
</li>
</ul>
</li>
<li>
<a href="#page2Submenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">
<i class="fas fa-copy"></i>
Sales
</a>
<ul class="collapse list-unstyled" id="page2Submenu">
<li>
<i class="icon-padnote"></i>Record Sale
</li>
<li>
<i class="icon-padnote"></i>Sale history
</li>
<li>
<i class="icon-padnote"></i>Search sale
</li>
</ul>
</li>
<li>
<a href="#page3Submenu" data-toggle="collapse" class="dropdown-toggle">
<i class="fas fa-copy"></i>
Orders
</a>
<ul class="collapse list-unstyled" id="page3Submenu">
<li>
<i class="icon-padnote"></i>Record Purchase
</li>
<li>
<i class="icon-padnote"></i>Purchase history
</li>
<li>
<i class="icon-padnote"></i>Search order
</li>
<li>
<i class="icon-padnote"></i>Supplier Replenishment
</li>
<li>
<i class="icon-padnote"></i>Item Replenishment
</li>
</ul>
</li>
<li>
<a href="#page4Submenu" data-toggle="collapse" class="dropdown-toggle">
<i class="fas fa-copy"></i>
Bases
</a>
<ul class="collapse list-unstyled" id="page4Submenu">
<li>
<i class="icon-padnote"></i>Supplier Base
</li>
<li>
<i class="icon-padnote"></i>Item Base
</li>
</ul>
</li>
</ul></nav>

While looking at your code, it does seem to push down properly? It does seem a bit glitchy though. It might be another part of your html or css that is causing the problem.
demo gif

The easiest way to get elements to be shown is to use the :hover event which you ARE using, but you seem to be doing it with lists. Try using a simpler method maybe?
CSS:
body {
font-family: Arial, Helvetica, sans-serif;
}
.hide {
display: none;
}
.main:hover + .hide {
display: block;
color: grey;
}
HTML:
<div class="main">
<p>Hover over me<p>
</div>
<div class="hide">
<p>Hello, World!</p>
</div>

Related

Hover dropdown menu out of screen

.sidebar-left .dropdown {
position: static;
}
.sidebar-left .dropdown .dropdown-menu {
position: absolute;
z-index: 10;
display: none;
}
.sidebar-left .dropdown:hover .dropdown-menu{
position: absolute;
display: block;
left: 63px;
transform: translateY(-50px);
}
.sidebar-left .dropdown:hover > .dropdown-menu{
display: block;
}
.sidebar-left.open .dropdown:hover .dropdown-menu{
position: absolute;
display: block;
left: 273px;
}
.sidebar-left.open li[aria-expanded="true"]:hover > .dropdown-menu{
display: none;
}
.sidebar-left.open .dropdown:hover > .dropdown-menu{
display: block;
}
.dropdown-menu{
position: absolute;
padding-top: 0;
padding-bottom: 0;
box-shadow: 2px 2px 2px 2px #222;
background-color: #4c5569;
border-radius: 1px;
}
.dropdown-menu li{
margin-top: 0;
margin-bottom: 0;
padding: 15px 25px;
min-width: 175px;
}
.dropdown-menu li a span {
font-size: .8rem;
line-height: 1rem;
color: #fff;
text-decoration: none;
}
.dropdown-menu li:hover {
background-color: rgba(255,255,255,.05);
}
<div class="sidebar-left" id="sidebar">
<div class="sidebar-header">
<div class="sidebar-title">Navigation</div>
<div class="sidebar-collapse" id="sidebar-collapse" data-bind="click: toggleOpen">
<i class="fa-solid fa-bars" ></i>
</div>
</div>
<div class="sidebar">
<div class="sidebar-content">
<nav class="sidebar_nav" role="navigation">
<ul id=sidebar-accordion class="sidebar_nav-main" data-bind="foreach: {data:items}">
<li class="sidebar-link dropdown" data-bind="css: {'active': $data.isActive() ? true : false}, attr: { 'data-target': '#collapse' + $index(), 'aria-expanded': false, 'data-toggle': 'collapse' } ">
<a href="javascript:void(0)" data-bind="attr: {'href': $data.parent_link}" class="sidebar_main-link">
<i data-bind="class: $data.icon"><i data-bind="class: $data.icon2"></i></i>
<span class="sidebar-item" data-bind="text: name"></span>
</a>
<ul class="dropdown-menu sidebar_submenu" data-bind="foreach: $data.children">
<li class="dropdown-item sidebar_submenu-item" data-bind="class: $data.className">
<span data-bind="text: name"></span>
</li>
</ul>
<div class="sidebar-subchild" id="sidebar-subchild" onclick="event.stopPropagation()">
<ul data-parent="#sidebar-accordion" class="collapse sidebar_submenu" data-bind="attr: { id: 'collapse' + $index()}, foreach: $data.children">
<li class="sidebar_submenu-item" data-bind="class: $data.isSelectModule">
<a target="_self" data-bind="attr: { 'href' : $data.link}"><span data-bind="text: $data.name"></span></a>
</li>
</ul>
</div>
</li>
</ul>
</nav>
</div>
</div>
</div>
Good Day, I am facing some problem in my hover dropdown submenu, if in the full size of browser, the submenu item of my last menu is only show two items but actually there have 5 items. How can I make the submenu showing upward to prevent the items be hidden? Also if I smaller the browser screen, the submenu also will be hidden from browser. I was using bottom: cal() before, but the position of submenu also will crashed. Is there any better solution?

How do I split up a navigation bar into two sections in the same line?

Here's my HTML:
<body>
<nav class="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="fas fa-bars"></i>
</span>
logo
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</nav>
</body>
Here's my CSS:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: "Josefin Sans", sans-serif;
}
.navbar {
font-size: 18px;
padding-bottom: 10px;
}
.main-nav {
list-style-type: none;
display: none;
}
.nav-links,
.logo {
text-decoration: none;
color: black;
}
.main-nav li {
text-align: center;
margin: 15px auto;
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
display: block;
}
And this is the output I'm getting:
I'd like my output to be like this instead (ignore the spacing difference, just my screenshot, but have them split in the center like so):
What's the best way of doing this?
I'm thinking of creating another unorder list and moving it, but I don't know how to do that.
Make use of justify-content: space-between;.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
ul {
list-style-type: none;
}
.nav-links, .logo {
text-decoration: none;
color: #000;
}
.navbar {padding: 20px;}
.navbar, ul {display: flex; flex-direction:row;}
ul li {padding: 0 5px;}
.wrapper {display:flex; justify-content: space-between; width:100%; }
<nav class="navbar">
logo
<div class="wrapper">
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
</ul>
<ul class="ul2">
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</div>
</nav>

Why does this CSS code make my drop down menu show only one item of 3?

I'm creating a website for my school soccer program and I'm trying to create a drop down menu with another drop down menu inside to show the "previous teams" and all of their items (roster, pictures, matches, etc.).
I've tried removing the position: absolute and while that makes the submenu show up, the buttons I created that should in theory expand to the actual links don't end up doing anything. When not removing the position: absolute, 1 item (the final item I add) shows up and I can interact with it.
The HTML code:
<div class="nav-link-wrapper-drops">
<button class="Team">
Previous Teams
<i class="fa fa-caret-down"></i>
</button>
<div class="nav-link-wrapper-down">
<button class="button-down">
> 2018/2019
<i class="fa fa-caret-down"></i>
</button>
<div class="nav-link-wrapper-twodown">
Roster
Schedule
Pictures
</div>
</div>
<div class="nav-link-wrapper-down">
<button class="button-down">
> 2017/2018
<i class="fa fa-caret-down"></i>
</button>
<div class="nav-link-wrapper-twodown">
Roster
Schedule
Pictures
</div>
</div>
<div class="nav-link-wrapper-down">
<button class="button-down">
> 2016/2017
<i class="fa fa-caret-down"></i>
</button>
<div class="nav-link-wrapper-twodown">
Roster
Schedule
Pictures
</div>
</div>
</div>
The CSS code going with this:
.nav-link-wrapper-drops:hover .nav-link-wrapper-down {
display: block;
}
.nav-link-wrapper-down .button-down {
border: none;
outline: none;
color: red;
background-color: inherit;
font-family: inherit;
text-transform: uppercase;
padding: 12px 16px;
}
.nav-link-wrapper-twodown {
display: none;
position: absolute;
background-color: navy;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 100%;
top: 0%;
}
.nav-link-wrapper-twodown a {
float: none;
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
left: 100%;
top: 0%;
}
.nav-link-wrapper-twodown a:hover {
background-color: white;
border-color: navy;
}
.nav-link-wrapper-down:hover .nav-link-wrapper-twodown {
display: block;
}
I expect the output to essentially create a "double" drop down menu where there are two levels to the drop down menu.
I'm not very familiar with HTML and I created the drop down menus with <button>s because of an online tutorial but on this site I've seen many people using <li> and <ul> so I'm also wondering if there IS a way to make it with <button>.
EDIT:
The inspiration for this style of navbar came from this website. It's eventually what I want my website to look like - with different colors - visually.
*ALL OF MY CODE CAN BE FOUND AT THIS GITHUB.
Is this what you are trying to do?
.button-down {
border: none;
outline: none;
color: red;
background-color: inherit;
font-family: inherit;
text-transform: uppercase;
padding: 12px 16px;
height: 20px;
}
.nav-link-wrapper-twodown {
display: none;
float: left;
background-color: navy;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 100%;
top: 0%;
}
.nav-link-wrapper-twodown a {
float: none;
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
left: 100%;
top: 0%;
}
.nav-link-wrapper-drops {
display: flex;
flex-direction: row;
}
.Team {
height: 20px;
}
.Team:hover + .nav-link-wrapper-down, .nav-link-wrapper-down:hover {
display:block;
}
.nav-link-wrapper-down {
display:none;
margin: 0;
}
.button-down:hover + .nav-link-wrapper-twodown, .nav-link-wrapper-twodown:hover {
display:flex;
flex-direction: column;
float: right;
}
ul {
list-style: none;
padding: 0;
}
.nav-link-wrapper-twodown a:hover {
background-color: white;
border-color: navy;
}
<div class="nav-link-wrapper-drops">
<button class="Team">
Previous Team
<i class="fa fa-caret-down"></i>
</button>
<ul class="nav-link-wrapper-down">
<li class="item">
<button class="button-down">
> 2018/2019
<i class="fa fa-caret-down"></i>
</button>
<ul class="nav-link-wrapper-twodown">
<li>Roster</li>
<li>Schedule</li>
<li>Pictures</li>
</ul>
</li>
<li class="item">
<button class="button-down second-btn">
> 2017/2018
<i class="fa fa-caret-down"></i>
</button>
<ul class="nav-link-wrapper-twodown">
<li>Roster</li>
<li>Schedule</li>
<li>Pictures</li>
</ul>
</li>
<li class="item">
<button class="button-down second-btn">
> 2016/2017
<i class="fa fa-caret-down"></i>
</button>
<ul class="nav-link-wrapper-twodown">
<li>Roster</li>
<li>Schedule</li>
<li>Pictures</li>
</ul>
</li>
</ul>
</div>
Not an exact answer for the code you provided, but consider refactoring your menu system to use nested lists. Here is a dead simple prototype: https://codepen.io/JimmyJames88/pen/xvzOyg
Then it's just a matter of using css rules to show/hide the sub UL's strategically.
<ul class="nav">
<li>
Menu item 1
<ul>
<li>
Menu item 1.1
<ul>
<li>
Menu item 1.1.1
</li>
</ul>
</li>
</ul>
</li>
<li>
Menu item 2
<ul>
<li>
Menu item 2.1
<ul>
<li>
Menu item 2.1.1
</li>
</ul>
</li>
</ul>
</li>
<li>
Menu item 3
<ul>
<li>
Menu item 3.1
<ul>
<li>
Menu item 3.1.1
</li>
</ul>
</li>
</ul>
</li>
</ul>
.nav > li ul {
display: none;
}
.nav li:hover > ul {
display: block;
}

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