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
Related
I have sticky left nav bar, I would like to active nav as per page, I did class active for related page nav items but now I moved to header single one master page now I added active class in any nav item the only one active nav shows whatever page I am is on. I need active item as per page nav, please help.
.navbar {
position: fixed;
background-color: #C8E8E9;
transition: width 600ms ease;
overflow: hidden;
z-index:9;
border-radius:0px!important;
top: 0;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
width: max-content;
font-family: 'Open Sans';
}
.nav-item {
width: 100%;
}
.nav-item a {
}
.nav-item .active {
background-color: #ffc20e!important;
}
.nav-item:last-child {
margin-top: auto;
}
.active-nav{
background-color:#FFDB72;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
color: #000000;
text-decoration: none;
/*filter: grayscale(100%) opacity(0.7);*/
transition: var(--transition-speed);
}
.nav-link:hover {
filter: grayscale(0%) opacity(1);
background: #FFDB72;
color: #000000;
}
.link-text {
display: none;
margin-left: 0rem;
padding-left: 21px;
font-size: 13px;
font-weight: 600;
margin-right:50px;
}
.nav-link-arrow{
width: 2rem;
min-width: 2rem;
margin: 0 1.5rem;
}
.nav-link-icon{
width: 0rem;
min-width:0rem;
margin: 0 1.5rem;
}
.nav-link svg {
width: 1rem;
min-width: 1rem;
margin: 0 1.5rem;
}
.fa-primary {
color: #ff7eee;
}
.fa-secondary {
color: #df49a6;
}
.fa-primary,
.fa-secondary {
transition: var(--transition-speed);
}
.logo {
font-weight: bold;
text-transform: uppercase;
margin-bottom: 1rem;
text-align: center;
font-size: 1.5rem;
letter-spacing: 0.3ch;
width: 100%;
}
.logo svg {
transform: rotate(0deg);
transition: var(--transition-speed);
filter: brightness(0.2) sepia(1) hue-rotate(180deg) saturate(5);
}
.logo-text
{
display: inline;
position: absolute;
left: -999px;
transition: var(--transition-speed);
font-size:16px;
}
.navbar:hover .logo svg {
transform: rotate(-180deg);
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo">
<a href="#" class="nav-link">
<span class="link-text logo-text">Menu</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-university nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 1</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-book nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 2</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-user nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 3</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-picture-o nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 4</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link pl-25">
<img src="images/image.png">
<span class="link-text">Nav 5</span>
</a>
</li>
</ul>
</nav>
Here i don't understand your question but here i understand a little bit what you want is nav active when clicked on one page, sorry if i misunderstood
Here I try my best to help and hope it helps
Here I added Jquery, you can try it
$(function(){
$('.navbar-nav a').on("click",function(){
$('.nav-link').removeClass('active');
$(this).addClass('active');
});
})
.navbar {
position: fixed;
background-color: #C8E8E9;
transition: width 600ms ease;
overflow: hidden;
z-index:9;
border-radius:0px!important;
top: 0;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
width: max-content;
font-family: 'Open Sans';
}
.nav-item {
width: 100%;
}
.nav-item a {
}
.nav-item .active {
background-color: #ffc20e!important;
}
.nav-item:last-child {
margin-top: auto;
}
.active-nav{
background-color:#FFDB72;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
color: #000000;
text-decoration: none;
/*filter: grayscale(100%) opacity(0.7);*/
transition: var(--transition-speed);
}
.nav-link:hover {
filter: grayscale(0%) opacity(1);
background: #FFDB72;
color: #000000;
}
.link-text {
display: none;
margin-left: 0rem;
padding-left: 21px;
font-size: 13px;
font-weight: 600;
margin-right:50px;
}
.nav-link-arrow{
width: 2rem;
min-width: 2rem;
margin: 0 1.5rem;
}
.nav-link-icon{
width: 0rem;
min-width:0rem;
margin: 0 1.5rem;
}
.nav-link svg {
width: 1rem;
min-width: 1rem;
margin: 0 1.5rem;
}
.fa-primary {
color: #ff7eee;
}
.fa-secondary {
color: #df49a6;
}
.fa-primary,
.fa-secondary {
transition: var(--transition-speed);
}
.logo {
font-weight: bold;
text-transform: uppercase;
margin-bottom: 1rem;
text-align: center;
font-size: 1.5rem;
letter-spacing: 0.3ch;
width: 100%;
}
.logo svg {
transform: rotate(0deg);
transition: var(--transition-speed);
filter: brightness(0.2) sepia(1) hue-rotate(180deg) saturate(5);
}
.logo-text
{
display: inline;
position: absolute;
left: -999px;
transition: var(--transition-speed);
font-size:16px;
}
.navbar:hover .logo svg {
transform: rotate(-180deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo">
<a href="#" class="nav-link">
<span class="link-text logo-text">Menu</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link active">
<i class="fa fa-university nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text ">Nav 1</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-book nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 2</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-user nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 3</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-picture-o nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 4</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link pl-25">
<img src="images/image.png">
<span class="link-text">Nav 5</span>
</a>
</li>
</ul>
</nav>
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>
Right Now this is my homepage:
I used css content to show the link texts when the user hovers over the icons. However, right now whichever icon you hover over, it will show the same text "home". My question is how can I set different text outputs for each icon/link . Thank you in advance.
Navbar.html:
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo">
<img src="{% static 'portfolio/logo.png' %}" alt="">
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-home "></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-cog"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-book"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-tasks"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-phone"></i>
</a>
</li>
</ul>
</nav>
_sidebar.scss:
.navbar{
position:fixed;
background-color: $navbg;
}
.navbar-nav{
list-style: none;
padding: 0;
margin: 0;
display:flex;
flex-direction: column;
align-items:center;
height: 100%;
}
.nav-item{
width:100%;
&:last-child {
margin-top: auto;
}
}
.nav-link{
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 5rem;
font-size: 2rem;
padding:1.5rem;
text-decoration: none;
i{
font-size: 3rem;
color: $navicon;
&:hover{
color:$icon-hover;
}
}
&:hover::after{
content : "Home";
position: absolute;
color:#12181b;
background: #b2becd;
right:-7rem;
border-radius: 0.5rem;
padding:0.5rem;
margin-left:2rem;
}
}
.logo{
display: flex;
align-items: center;
justify-content: center;
margin-top: 2rem;
margin-bottom: 2.5rem;
width: 100%;
img{
width:60%;
}
}
Using content isn't the correct way to add dynamic contents, that to to a compiled SCSS. You need to add another element, keep it hidden normally and show it when user hovers over it's parent.
This way you can add proper content for each icon whether statically or dynamically, following is a proof of concept:
.navbar {
position: fixed;
background-color: black;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.nav-item {
width: 100%;
}
.nav-item:last-child {
margin-top: auto;
}
.nav-link {
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 5rem;
font-size: 2rem;
padding: 1.5rem;
text-decoration: none;
}
.nav-link i {
font-size: 3rem;
color: white;
}
.nav-link i:hover {
color: red;
}
.label {
display: none;
}
.nav-item:hover .label {
display: block;
position: absolute;
color: #12181b;
background: #b2becd;
right: -7rem;
border-radius: 0.5rem;
padding: 0.5rem;
margin-left: 2rem;
}
.logo {
display: flex;
align-items: center;
justify-content: center;
margin-top: 2rem;
margin-bottom: 2.5rem;
width: 100%;
}
.logo img {
width: 60%;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo"><img src="{% static 'portfolio/logo.png' %}" alt="">
</li>
<li class="nav-item">
<i class="fas fa-home "></i><span class="label">First Icon</span></li>
<li class="nav-item"><i class="fas fa-cog"></i><span class="label">Second Icon</span></li>
<li class="nav-item"><i class="fas fa-book"></i><span class="label">Third Icon</span></li>
<li class="nav-item"><i class="fas fa-tasks"></i><span class="label">fourth Icon</span></li>
<li class="nav-item"><i class="fas fa-phone"></i><span class="label">Fifth Icon</span></li>
</ul>
</nav>
You can use data attribute in html and call it from css for diffrent content values
// HTML
<li class="nav-item">
<a href="" class="nav-link" data-title="home">
<i class="fas fa-home"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link" data-title="setting">
<i class="fas fa-cog"></i>
</a>
</li>
...
// CSS
.nav-link:hover::after {
content: attr(data-title); // added
position: absolute;
color: #12181b;
background: #b2becd;
right: -7rem;
border-radius: 0.5rem;
padding: 0.5rem;
margin-left: 2rem;
}
I am designing an electron application with a tabpane. However when the user makes the window smaller or adds more tabs the scrollbar that is supposed to let users see all the tabs does not work correctly. The scrollbar allows for a little movement but most of the tabs overflow regardless. I have uploaded a stripped down code snippet version of the app here so you can see my problem in more detail.
body {
margin: 0;
width: 100vw;
height: 100vh;
overflow-x: hidden;
display: flex;
flex-direction: column;
}
.window {
position: relative;
display: flex;
flex-grow: 1;
}
.window__content {
display: flex;
flex-direction: column;
flex-grow: 1;
}
ul {
padding: 0;
margin: 0;
list-style: none;
}
.action-bar {
display: flex;
flex-shrink: 0;
flex-direction: column;
overflow: hidden;
width: 44px;
transition: width 0.2s ease;
}
.action-bar .action-bar__item {
white-space: nowrap;
padding: 6px 12px;
}
.action-bar i {
font-size: 20px;
margin-right: 22px;
}
.action-bar__spacer {
flex-grow: 1;
}
.console {
position: relative;
height: 44px;
transition: all 0.5s ease;
min-height: 44px;
max-height: 50%;
overflow: hidden;
font-size: 13px;
}
.tabpane {
display: flex;
flex-grow: 1;
flex-direction: column;
height: 100%;
position: relative;
}
.tabpane .tabpane__tabs {
position: relative;
white-space: nowrap;
flex-shrink: 0;
overflow-x: auto;
}
.tabpane .tabpane__tabs li {
position: relative;
display: inline-block;
padding: 8px;
font-size: 13px;
min-width: 80px;
max-width: 160px;
border: solid #1E1E1E;
border-width: 0 1px;
margin-right: -5px;
color: #8D8D8D;
background: #333333;
}
.tabpane .tabpane__tabs li:hover {
cursor: pointer;
}
.tabpane .tabpane__tabs li.tab--active {
border-top-width: 1px;
padding-top: 7px;
background: #1E1E1E;
color: white;
z-index: 2;
}
.tabpane .tabpane__tabs li i {
float: right;
visibility: hidden;
}
.tabpane .tabpane__tabs li:hover i, .tabpane .tabpane__tabs li.tab--active i {
visibility: visible;
}
#draggableTab {
color: #8D8D8D;
background-color: rgba(51,51,51,0.9);
outline: 1px solid rgba(64,64,64,0.9);
padding: 7px 8px;
font-size: 13px;
min-width: 80px;
cursor: pointer;
position: fixed;
z-index: 10030;
pointer-events: none;
white-space: nowrap;
}
#draggableTab i {
color: white;
float: right;
opacity: 0.3;
position: relative;
z-index: 9999;
}
.tabpane__panes {
position: relative;
display: flex;
flex-grow: 1;
overflow-y: scroll;
}
.tabpane__panes li {
display: none;
}
.tabpane__panes li.pane--active {
display: initial;
flex: 1;
padding: 0 44px;
background: #1E1E1E;
}
/* Colors */
.theme--dark {
color: white;
}
.shade--light {
background: #333333;
}
.shade--neutral {
background: #252526;
}
.shade--dark {
background: #1E1E1E;
}
.shade--darker {
background: #141516;
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="UTF-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
</head>
<body class="theme--dark shade--dark">
<div class="window">
<ul class="action-bar shade--neutral">
<li class="action-bar__item" title="Expand"><i class="fa fa-bars" aria-hidden="true"></i></li>
<li class="action-bar__item" title="Home" data-template="home"><i class="fa fa-home" aria-hidden="true"></i>Home</li>
<li class="action-bar__item" title="Search" data-template="search"><i class="fa fa-search" aria-hidden="true"></i>Search</li>
<li class="action-bar__item" title="Download" data-template="download"><i class="fa fa-download" aria-hidden="true"></i>Download</li>
<li class="action-bar__item" title="Statistics" data-template="statistics"><i class="fa fa-pie-chart" aria-hidden="true"></i>Statistics</li>
<li class="action-bar__item" title="Help" data-template="help"><i class="fa fa-question-circle" aria-hidden="true"></i>Help</li>
<li class="action-bar__divider shade--light"></li>
<li class="action-bar__item" title="Lights On"><i class="fa fa-sun-o" aria-hidden="true"></i>Lights On</li>
<li class="action-bar__item" title="Console"><i class="fa fa-code" aria-hidden="true"></i>Console</li>
<li class="action-bar__spacer"></li>
<li class="action-bar__item" title="Lock"><i class="fa fa-lock" aria-hidden="true"></i>Lock</li>
<li class="action-bar__item" title="Settings" data-template="settings"><i class="fa fa-cog" aria-hidden="true"></i>Settings</li>
</ul>
<div class="window__content">
<div class="tabpane">
<ul class="tabpane__tabs shade--neutral">
<li template="home" source="undefined" class="tab--active left">
Home
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_1" source="undefined" class="">
page 1
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_2" source="undefined" class="">
page 2
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_3" source="undefined" class="">
page 3
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_4" source="undefined" class="">
page 4
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_5" source="undefined" class="">
page 5
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_6" source="undefined" class="">
page 6
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_7" source="undefined" class="">
page 7
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_8" source="undefined" class="">
page 8
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
</ul>
<ul class="tabpane__panes">
<li class="pane--active">
<h1>Hello</h1>
<div style="max-width: 400px;">
<p>Try resizing your browser window until some tabs are hidden and a scrollbar appears.</p>
<p>I have removed the JavaScript for this example don't expect buttons to work. The scrollbar however needs to work no matter the height of the console window below the tabs or the width of the action bar to the left.</p>
</div>
</li>
<li>page for page 2</li>
<li>page for page 3</li>
<li>page for page 4</li>
<li>page for page 5</li>
<li>page for page 6</li>
<li>page for page 7</li>
<li>page for page 8</li>
</ul>
</div>
<div class="console console--is-closed shade--darker">
<div class="console__close"><span class="lnr lnr-cross"></span></div>
<div class="console__area">
<div class="console__resize-bar"></div>
<p><span class="console__point">Console> </span><input type="text" class="console__input"></p>
</div>
</div>
</div>
</div>
</body>
</html>
I think this would work for you.
just remove the flex-grow: 1; from .window__content and add width: calc(100% - 44px);
width: calc(100% - 44px); == width: calc(100% - .action-bar[width]);
body {
margin: 0;
width: 100vw;
height: 100vh;
overflow-x: hidden;
display: flex;
flex-direction: column;
}
.window {
position: relative;
display: flex;
flex-grow: 1;
}
.window__content {
display: flex;
flex-direction: column;
width: calc(100% - 44px);
}
ul {
padding: 0;
margin: 0;
list-style: none;
}
.action-bar {
display: flex;
flex-shrink: 0;
flex-direction: column;
overflow: hidden;
width: 44px;
transition: width 0.2s ease;
}
.action-bar .action-bar__item {
white-space: nowrap;
padding: 6px 12px;
}
.action-bar i {
font-size: 20px;
margin-right: 22px;
}
.action-bar__spacer {
flex-grow: 1;
}
.console {
position: relative;
height: 44px;
transition: all 0.5s ease;
min-height: 44px;
max-height: 50%;
overflow: hidden;
font-size: 13px;
}
.tabpane {
display: flex;
flex-grow: 1;
flex-direction: column;
height: 100%;
position: relative;
}
.tabpane .tabpane__tabs {
position: relative;
white-space: nowrap;
flex-shrink: 0;
overflow-x: auto;
}
.tabpane .tabpane__tabs li {
position: relative;
display: inline-block;
padding: 8px;
font-size: 13px;
min-width: 80px;
max-width: 160px;
border: solid #1E1E1E;
border-width: 0 1px;
margin-right: -5px;
color: #8D8D8D;
background: #333333;
}
.tabpane .tabpane__tabs li:hover {
cursor: pointer;
}
.tabpane .tabpane__tabs li.tab--active {
border-top-width: 1px;
padding-top: 7px;
background: #1E1E1E;
color: white;
z-index: 2;
}
.tabpane .tabpane__tabs li i {
float: right;
visibility: hidden;
}
.tabpane .tabpane__tabs li:hover i, .tabpane .tabpane__tabs li.tab--active i {
visibility: visible;
}
#draggableTab {
color: #8D8D8D;
background-color: rgba(51,51,51,0.9);
outline: 1px solid rgba(64,64,64,0.9);
padding: 7px 8px;
font-size: 13px;
min-width: 80px;
cursor: pointer;
position: fixed;
z-index: 10030;
pointer-events: none;
white-space: nowrap;
}
#draggableTab i {
color: white;
float: right;
opacity: 0.3;
position: relative;
z-index: 9999;
}
.tabpane__panes {
position: relative;
display: flex;
flex-grow: 1;
overflow-y: scroll;
}
.tabpane__panes li {
display: none;
}
.tabpane__panes li.pane--active {
display: initial;
flex: 1;
padding: 0 44px;
background: #1E1E1E;
}
/* Colors */
.theme--dark {
color: white;
}
.shade--light {
background: #333333;
}
.shade--neutral {
background: #252526;
}
.shade--dark {
background: #1E1E1E;
}
.shade--darker {
background: #141516;
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="UTF-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
</head>
<body class="theme--dark shade--dark">
<div class="window">
<ul class="action-bar shade--neutral">
<li class="action-bar__item" title="Expand"><i class="fa fa-bars" aria-hidden="true"></i></li>
<li class="action-bar__item" title="Home" data-template="home"><i class="fa fa-home" aria-hidden="true"></i>Home</li>
<li class="action-bar__item" title="Search" data-template="search"><i class="fa fa-search" aria-hidden="true"></i>Search</li>
<li class="action-bar__item" title="Download" data-template="download"><i class="fa fa-download" aria-hidden="true"></i>Download</li>
<li class="action-bar__item" title="Statistics" data-template="statistics"><i class="fa fa-pie-chart" aria-hidden="true"></i>Statistics</li>
<li class="action-bar__item" title="Help" data-template="help"><i class="fa fa-question-circle" aria-hidden="true"></i>Help</li>
<li class="action-bar__divider shade--light"></li>
<li class="action-bar__item" title="Lights On"><i class="fa fa-sun-o" aria-hidden="true"></i>Lights On</li>
<li class="action-bar__item" title="Console"><i class="fa fa-code" aria-hidden="true"></i>Console</li>
<li class="action-bar__spacer"></li>
<li class="action-bar__item" title="Lock"><i class="fa fa-lock" aria-hidden="true"></i>Lock</li>
<li class="action-bar__item" title="Settings" data-template="settings"><i class="fa fa-cog" aria-hidden="true"></i>Settings</li>
</ul>
<div class="window__content">
<div class="tabpane">
<ul class="tabpane__tabs shade--neutral">
<li template="home" source="undefined" class="tab--active left">
Home
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_1" source="undefined" class="">
page 1
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_2" source="undefined" class="">
page 2
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_3" source="undefined" class="">
page 3
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_4" source="undefined" class="">
page 4
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_5" source="undefined" class="">
page 5
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_6" source="undefined" class="">
page 6
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_7" source="undefined" class="">
page 7
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_8" source="undefined" class="">
page 8
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
</ul>
<ul class="tabpane__panes">
<li class="pane--active">
<h1>Hello</h1>
<div style="max-width: 400px;">
<p>Try resizing your browser window until some tabs are hidden and a scrollbar appears.</p>
<p>I have removed the JavaScript for this example don't expect buttons to work. The scrollbar however needs to work no matter the height of the console window below the tabs or the width of the action bar to the left.</p>
</div>
</li>
<li>page for page 2</li>
<li>page for page 3</li>
<li>page for page 4</li>
<li>page for page 5</li>
<li>page for page 6</li>
<li>page for page 7</li>
<li>page for page 8</li>
</ul>
</div>
<div class="console console--is-closed shade--darker">
<div class="console__close"><span class="lnr lnr-cross"></span></div>
<div class="console__area">
<div class="console__resize-bar"></div>
<p><span class="console__point">Console> </span><input type="text" class="console__input"></p>
</div>
</div>
</div>
</div>
</body>
</html>
Hope this was helpfull for you.
The problem is the width of your tabpane. It should not be 100% (default), since there is the action bar on the left side
.tabpane {
display: flex;
flex-grow: 1;
flex-direction: column;
height: 100%;
position: relative;
}
add
width:90%;
or whatever 100% - 44px would be
I think;
.window__content {
width: 90%; // add
}
#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