CSS Vertical Menu with submenu callouts overlapping - html

Its been a while - but I found myself a new exiting hobby in web development, and I am hoping that you can help me overcome the following issue:
I am working on a personal website. Content etc. is all preliminary. My main focus is the vertical menu on the left hand side. While I am pretty happy with the appearance so far, there are still some questions:
1) I had to set the transition as ease out to >0s, so that I have enough time between the main-menu hover and the hover over the sub-menu. Because of this, if I hover between main-menu items, they will briefly overlap due to the phase out. Is there a way to work around this?
(the focus selector might be an option, but that requires to click the menu item, and I prefer the hover)
2) The sub-menu is aligned to the top of the li of the main-menu. Because of that, the last item's sub (Testing) exceeds the boundaries of the page, giving whitespace below the page. Is there a way to make the sub-menu shift up if it presses against the edge of the overall body?
I probably could give it a different tag and design it differently, am I am hoping there is a more general solution.
3) Minor issue: When switching from main-menu hover to sub-menu hover, the main-icon "blinks" very briefly. Is that normal behavior? Certainly isn't pretty.
4) Last but not least: As this is my first time doing a website, I would be more than grateful to get your general feedback on inefficiencies in the code, so I can be more lean in the future.
(see updated fiddle below - full code removed to save space.)
Thanks for your help!
EDIT
THanks for your answers - issue #1 has been solved using the approaches you outlined!
However, the last submenu still gives me a bit a headache.
If I use the "last-child" selector, and the code added below, it will not change anything. However, if I give the last "bubble" a different tag, using the exact same code, the bubble will align to the bottom of the last main-menu item, but the containing UL remains defiant.
As you can see from the original CSS, the last "relative" is the main-menu IL, so shouldn't the submenu and the containing UL both align to the bottom of their respective parent/grandparent?
using a dedicated, different tag for the last-child "bubble_last
Using the last-child selector
and the accompanying new code (updated fiddle with full code: Heres the Fiddle ...use large screen for the result to see the alignment issue):
.navigation ul li:last-child {
border: solid orange;
}
.navigation .bubble_last{
position: absolute;
margin-top: 0%;
padding: 0px;
left: 60px;
bottom: 0px;
width: 400px;
height: 200px;
border: solid red;
}
.navigation .bubble_last ul{
position: absolute;
left: 0;
bottom: : 0px;
margin-top: 0px;
padding: 0px;
width: 20vw;
height: 100px;
font-size: 15px;
font-size: 1.2vw;
font-weight: 400;
border: solid blue;
margin-left: 28%;
display: block;
}
.navigation .bubble_last ul li {
list-style: none;
background-color: none;
border-radius: 3px;
height: 2vw;
line-height: 1.2vw;
width: 20vw;
position: relative;
padding-top: 0px;
margin: 0;
padding: 0;
}

Instead of adding a transition delay on .bubble, you just need to make the .bubble class wide enough (and start behind the main li trigger with a left: 60px) so that the hover will be continuous:
.navigation .bubble {
position: absolute;
margin-top: 0%;
padding: 0px;
left: 60px;
top: 0px;
width: 200px;
height: 100%;
background-color: none;
}
Then just add a margin-left to the submenu:
.navigation ul li ul {
margin-left: 20px;
}
To fix your second issue, simply add the following CSS to make the last submenu positioned relative to the bottom of the nav item:
ul li ul.subm:last-child {
top: auto;
bottom:0px;
}
Updated Demo: JSFiddle

How about this? Adjust your navigation to use the nav element, set it to use flex box, adjust that so it fits the height of your page, and then adjust the transition effects so they transition in and out properly.
I hope this helps.
#import url("http://fonts.googleapis.com/css?family=Roboto");
* {
border: none;
margin: 0;
padding: 0;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: Roboto Condensed;
box-sizing: border-box;
}
.landing {
display: table;
margin: auto;
width: 100%;
height: 100%;
background: url("https://imageshack.com/i/poXkyeIYj") 50% 50% no-repeat;
background-size: cover;
top: 0;
position: relative;
z-index: 1;
}
.landing .welcome {
margin: 10px;
width: 89%;
color: #FFF;
text-align: center;
display: table-cell;
vertical-align: middle;
position: absolute;
left: 10%;
top: 30%;
}
#mug {
background: url("https://imageshack.com/i/pmJaAuFkj") 50% 50% no-repeat;
background-size: cover;
border: solid 3px #FFF;
/*max-width: 20%;
max-height: 20%; */
width: 150px;
height: 150px;
margin: auto;
border-radius: 100%;
}
nav {
width: 50px;
height: 100%;
flex: 1;
display: flex;
justify-content: center;
flex-direction: column;
}
nav img {
max-width: 50px;
max-height: 50px;
}
.nav ul {
*zoom: 1;
list-style: none;
margin: 0;
padding: 0;
-ms-flex: 0 100px;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
justify-content: space-between;
margin-top: 0px;
padding: 0px;
width: 11vw;
height: auto;
font-size: 15px;
font-size: 1.2vw;
font-weight: 400;
border-color: none;
}
nav ul li {
background-color: rgba(222, 225, 229, 0.8);
border-radius: 3px;
width: 100%;
font-size: 15px;
font-size: 1.2vw;
font-weight: 900;
}
.nav ul:before,
.nav ul:after {
content: "";
display: block;
}
.nav ul:after {
clear: both;
}
.nav ul>li {
position: relative;
}
.nav a {
display: block;
padding: 10px 20px;
line-height: 1.2em;
color: #fff;
border-left: 1px solid #595959;
text-decoration: none;
color: #FFF;
}
.nav a:hover {
text-decoration: none;
background-color: rgba(242, 93, 38, 0.8);
}
.nav li ul {
background: #273754;
}
.nav li ul li {
width: 200px;
}
.nav li ul a {
border: none;
}
.nav li ul a:hover {
background: rgba(0, 0, 0, 0.2);
}
.nav li ul {
position: absolute;
left: 11vw;
top: 0;
z-index: 1;
visibility: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: 200ms ease;
-moz-transition: 200ms ease;
-o-transition: 200ms ease;
transition: 200ms ease;
}
.nav ul>li:hover ul {
visibility: visible;
opacity: 1;
filter: alpha(opacity=100);
}
span.caption {
display: none;
}
<body>
<div class="landing">
<div class="welcome">
<div id="mug">
</div>
<h1>Welcome to my personal Website!</h1>
<h2>On this site you will find a information about the person, the profession and other stuff about me. Enjoy!</h2>
</div>
<!-- cleaned up the navigation, nested it within the rest of the page, and adjusted the css -->
<nav class="nav">
<ul>
<li>
<img src="https://imageshack.com/i/potj2pVwp"> <span class="caption">Home</span>
</li>
<li>
<img src="https://imageshack.com/i/pntQ9nVMp"><span class="caption">About Me</span>
<ul>
<li>What I do</li>
<li>Motorcycling</li>
<li>Music</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/po4WFq6Yp"><span class="caption">Professional</span>
<ul>
<li>Current Employment</li>
<li>Working Experience</li>
<li>Education</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/pmcfm7Kbp"> <span class="caption">Projects</span>
<ul>
<li>Subnav Item</li>
<li>Subnav Item</li>
<li>Subnav Item</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/pnM0Fmgrp"> <span class="caption">Misc</span>
<ul>
<li>Subnav Item</li>
<li>Subnav Item</li>
<li>Subnav Item</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/poqRnk6ap"> <span class="caption">Testing</span>
<ul>
<li>Subnav Item</li>
<li>Subnav Item</li>
<li>Subnav Item</li>
</ul>
</li>
<li>
<img src="https://imageshack.com/i/pmc8tts9p"> <span class="caption">Contact</span>
</li>
</ul>
</nav>
</div>

Related

How to fix this dropdown navbar

I am writing a navigation bar with a dropdown option.
I have 2 problems: I can't get the dropdown to position properly under the menu, + also when I try to move the mouse to click on the elements in the dropdown submenu it closes as soon as I move.
Can anyone suggest a fix?
Thanks
On codepen:
https://codepen.io/-royqooe/pen/GRxaVbm
/* CSS section for home */
.navtop {
position: relative;
background-color: #333333;
height: 50px;
width: 100%;
border: 0;
}
.navtop div {
display: flex;
margin: 0 auto;
height: 100%;
}
.navtop div h1,
.navtop div a {
display: inline-flex;
align-items: center;
}
.navtop div h1 {
flex: 1;
font-size: 24px;
padding: 0;
margin: 0;
margin-left: 2%;
color: #f5f8ff;
font-weight: normal;
}
.navtop div a {
padding: 0 12px;
text-decoration: none;
color: #c1c4c8;
font-weight: bold;
}
.navtop div a i {
padding: 2px 8px 0 0;
}
.navtop div a:hover {
color: #66ccff;
}
/* sequel for home and navbar */
nav.navtop {
font-family: monospace;
}
.navtop>.navbar>ul {
list-style: none;
margin: 0;
padding-left: 0;
}
.navtop li {
display: block;
float: left;
padding: 0.5rem 0;
position: relative;
text-decoration: none;
transition-duration: 0.3s;
}
.navtop ul li ul {
background: red;
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
left: 0;
display: none;
}
.navtop ul li:hover>ul,
.navtop ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
.navtop ul li ul li {
clear: both;
width: 100%;
}
#media screen and (max-width: 760px) {
.topbar-text {
display: none;
}
}
<nav class="navlol navtop" role="navigation">
<div class="navbar">
<h1>Websitee Title</h1>
<ul>
<li><i class="fa-solid fa-file"></i><span class="topbar-text">Home</span></li>
<li>Two
<ul class="dropdownnn">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li class="navelements">Three</li>
<li><i class="fas fa-user-circle"></i><span class="topbar-text">Profile</span></li>
<li><i class="fas fa-sign-out-alt"></i><span class="topbar-text">Logout</span></li>
</ul>
</div>
</nav>
got an easy fix for you:
add this
.navtop li {
min-height:25px;
}
the issue is that that menu li was way shorter than the others to the sides due to the icons, even better maybe is instead adding this instead:
.navtop li {
height:100%
}
both worked for me
In the screenshot, the yellow color is the area that <li> element is covering. You can see there is a gap between <li> element and submenu. When you try to move the mouse to submenu, your cursor goes out of yellow area and the submenu hides.
The solution would be to position the submenu so it starts exactly after yellow area and make sure there is no gap. Apply margin-top of 0.5rem on submenu instead of 1rem.

Adding space between divs in flexbox

I want to ask about good practive in making spacing between two divs which have flexbox. For example:
header {
background-image: radial-gradient(circle, #72d6c9, #54d1ed, #7ac5ff, #bcb2fe, #f29cd9);
height: 80px;
}
.menu-section {
display: flex;
}
.nav-logo {
color: #e00986;
font-size: 25px;
margin: 0;
padding-left: 15px;
line-height: 80px;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
}
nav ul li {
display: inline-block;
width: 150px;
position: relative;
}
nav ul li a {
text-decoration: none;
line-height: 80px;
padding: 0 10px;
display: block;
color: #e00986;
}
nav ul li a:hover {
color: #FFF;
transition-duration: 2s;
}
<header>
<nav class="menu-section">
<h1 class="nav-logo">Love &#9825 Cookies</h1>
<ul>
<li>Strona główna</li>
<li>Ciastka
<ul>
<li>Torty</li>
<li>Babeczki</li>
<li>Bezy</li>
<li>Ciasta</li>
</ul>
</li>
<li>Kontakt</li>
</ul>
</nav>
</header>
Of course I can give margin-left: 550px to nav ul and it will be okay, but I don't think so that is the good practice. What's your opinion in this topic?
All you gotta do is make the parent of those two div's (the left logo and the right menu items) a display flex and justify-content: space-between or justify-content: space-around like so
.parent-div {
display:flex;
justify-content: space-between; //or space-around
}
.child-left {//doesn't matter what you put in here just so long as its a div}
.child-right {//doesn't matter what you put in here just so long as its a div}
If you have anymore question, this is where I go if I need help figuring out how to use flex: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I guess what you need is to move your navigation menu to right, reading the comments.
So solution to this would be giving space to left for your navigation(menu links). Yes you can definitely use margin-left but you do not need to specify exact pixels.
Better would be giving margin-left:auto, so that remaining space would be left on left side of your Navigation
Solution:
header {
background-image: radial-gradient(circle, #72d6c9, #54d1ed, #7ac5ff, #bcb2fe, #f29cd9);
height: 80px;
}
.menu-section {
display: flex;
}
.nav-logo {
color: #e00986;
font-size: 25px;
margin: 0;
padding-left: 15px;
line-height: 80px;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
margin-left:auto; /*ADDED HERE - THIS IS THE TRICK :)*/
}
nav ul li {
display: inline-block;
width: 150px;
position: relative;
}
nav ul li a {
text-decoration: none;
line-height: 80px;
padding: 0 10px;
display: block;
color: #e00986;
}
nav ul li a:hover {
color: #FFF;
transition-duration: 2s;
}
<header>
<nav class="menu-section">
<h1 class="nav-logo">Love &#9825 Cookies</h1>
<ul>
<li>Strona główna</li>
<li>Ciastka
<ul>
<li>Torty</li>
<li>Babeczki</li>
<li>Bezy</li>
<li>Ciasta</li>
</ul>
</li>
<li>Kontakt</li>
</ul>
</nav>
</header>
Hope this helps you.
.nav-logo
{
color: #e00986;
font-size: 25px;
margin-right: 100px;
padding-left: 15px;
line-height: 80px;
}
Use margin for outside spacing:)!

How to make border-bottom animation & ignore padding

I'm trying to make a navigation bar with a border-bottom as the hover effect which purpose is to follow the user mouseover and highlight the item. However, the border-bottom is including the padding of its parent, which I don't like. Using padding: 0px; doesn't do it.
Here's what I've got so far, bear with me since I'm fairly new to HTML & CSS and this is my first time making a website:
*{
padding: 0px;
margin: 0px;
}
#navdiv ul {
width: 100%;
height: 80px;
line-height: 80px;
vertical-align: middle;
background: #333;
margin-top: 5px;
}
#container {
margin-left: 200px;
margin-right: 200px;
}
#navdiv ul a {
width: 80%;
text-decoration: none;
color: #f2f2f2;
padding: 15px;
font-size: 16px;
}
#navdiv ul li {
height: 63px;
list-style-type: none;
float: right;
}
#navdiv ul li:hover {
border-bottom: 5px solid #FF9933;
transition: all 0.3s ease-in-out;
}
#highlight {
display: inline-block;
line-height: 1em;
padding: 0;
border-bottom: 5px solid #FF9933;
}
#navdiv img {
width: auto;
height: auto;
max-width: 100%;
max-height: 60px;
vertical-align: middle;
}
<nav>
<div id="Maindiv">
<div id="navdiv">
<ul>
<div id="container">
<img src="../img/menu-logo.png" alt="Menu Logo">
<li>Item 4</li>
<li>Item 3</li>
<li>Item 2</li>
<li>Item 1</li>
</div>
</ul>
</div>
</div>
</nav>
As you can see, the orange border-bottom is taking "Item 1" padding which is making the border-bottom larger than it's content, which I find it ugly and I would like to fix it.
While at it, is there a way to make the border-bottom animation come from the left to right? If so, is there also a way to make it "smart" enough to know that if the user's cursor comes from the left of the item, it should animate from "left to right" and if the cursor comes from the right animate it from "right to left" accordingly?
I would also love to make it follow the user cursor instead of instantly disappearing after leaving the previous item and immediately appearing once the next item is hovered.
Sorry for the long post, I've got so many questions and so little luck while troubleshooting using google with the little knowledge that I know.
Massive thanks!
- Kay.
Removing width: 80%; from #navdiv ul a will fix the larger border-bottom issue.
Please find below for left-to-right border-bottom effect.
https://codepen.io/julysfx/pen/qXBzYL
The reason for the border looking like that is because the border is around the outside of the HTML element. Padding is within the element so the border will incorporate that and thus do a border at that boundary. This stack overflow question explains this with diagrams:
Difference between margin and padding?
You might want to change to using margin to space out the items. Also, width: 80% might also make the border look a bit longer than you imagined. You could either increase the margin between items, or if you really want the items to be 80% wide, you could have a parent div which is 80% width so that it doesn't affect the border.
Is this more what you are looking for?
*{
padding: 0px;
margin: 0px;
}
.slider {
position: absolute;
display:block;
left: 0;
top: 90%;
margin: 0 auto;
height: 2px;
width: 0%;
border-bottom: 5px solid #FF9933;
transition: width 1s ease;
}
#navdiv {
background: #333;
}
#navdiv ul {
width: 100%;
display: inline;
}
#container {
margin-left: 200px;
margin-right: 200px;
height: 63px;
line-height: 63px;
}
#navdiv ul a {
text-decoration: none;
color: #f2f2f2;
font-size: 16px;
}
#navdiv ul li {
list-style-type: none;
float: right;
position:relative;
display:inline;
background-color: red;
line-height: 29px;
margin-top: 16px;
margin-right: 10px;
}
#navdiv ul li:hover .slider {
border-bottom: 5px solid #FF9933;
transition: all 0.3s ease-in-out;
width: 100%;
}
#highlight {
display: inline-block;
line-height: 1em;
padding: 0;
border-bottom: 5px solid #FF9933;
}
#navdiv img {
width: auto;
max-width: 100%;
}
<nav>
<div id="Maindiv">
<div id="navdiv">
<div id="container">
<img src="../img/menu-logo.png" alt="Menu Logo">
<ul>
<li>
Item 5
<span class="slider"></span>
</li>
<li>
Item 4
<span class="slider"></span>
</li>
<li>
Item 3
<span class="slider"></span>
</li>
<li>
Item 2
<span class="slider"></span>
</li>
<li id="highlight">
Item 1
<span class="slider"></span>
</li>
</ul>
</div>
</div>
</div>
</nav>

Align ::before pseudo element with list item contents

I have a side navigation I'm building, and it needs to be fully keyboard accessible as well as have the links themselves nested in list items. Everything else works fine, but I've been asked to produce a hover animation which is an animated pseudo element.
I've got most of that done, being the structure of the nav and the animation. However, the animated ::before element always seems to show up at the top of the list item, and will push the anchor down by whatever height I've set. I've tried both height:inherit and 100% for the ::before content, but that doesn't work.
The ideal behavior is that the content would animate in-line with the anchor from the bottom to the top, and simply occupy the height (100%) of the li element with my specified width.
Note: I can't use list-style:none because a screen reader will not identify how many items are in the list.
EDIT: took out the button element. Just focusing on the menu.
Here's a CodePen: https://codepen.io/anon/pen/EZbLMY
Feel free to fork it.
HTML:
<div id="mySidenav" class="sidenav" aria-label="Menu" aria-hidden="true">
<nav>
<ul role="navigation">
<li id="about">About</li>
<li id="services">Services</li>
<li id="clients">Clients</li>
<li id="contact">Contact</li>
</ul>
</nav>
</div>
CSS:
/* The side navigation menu */
.sidenav {
height: 100%;
width: 250px;
position: absolute;
z-index: 2;
top: 0;
background-color: #fff;
overflow-x: hidden;
padding-top: 60px;
}
.showOverlay{
display: block !important;
}
/* The navigation menu links */
.sidenav a{
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #000;
display: block;
width: inherit;
}
/*Clean up space between elements*/
.sidenav nav ul{
padding: 0;
margin: 0;
}
.sidenav nav ul li::before{
content:"";
width: 4px;
height: 0px;
display: block;
background-color: #000000;
}
.sidenav nav ul li:hover::before{
height: 20px;
transition: 0.3s ease-out;
padding-left: 2px;
}
Change the position of the ::before element to absolute. Also, to line things up neatly, add a position:relative to the li elements.
/* The side navigation menu */
.sidenav {
height: 100%;
width: 250px;
position: absolute;
z-index: 2;
top: 0;
background-color: #fff;
overflow-x: hidden;
padding-top: 60px;
}
.showOverlay {
display: block !important;
}
/* The navigation menu links */
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #000;
display: block;
width: inherit;
}
/*Clean up space between elements*/
.sidenav nav ul {
padding: 0;
margin: 0;
}
/*Make li elements relative, so that the before elements are positioned correctly*/
.sidenav nav ul li {
position: relative;
}
.sidenav nav ul li::before {
content: "*";
width: 4px;
height: 0px;
display: block;
background-color: #000000;
/*Add absolute positioning*/
position: absolute;
top: 8px;
}
.sidenav nav ul li:hover::before {
height: 20px;
transition: 0.3s ease-out;
padding-left: 2px;
}
<div id="mySidenav" class="sidenav" aria-label="Menu" aria-hidden="true">
<nav>
<ul role="navigation">
<li id="about">About</li>
<li id="services">Services</li>
<li id="clients">Clients</li>
<li id="contact">Contact</li>
</ul>
</nav>
</div>

Change css of list item before an after the item that is being hovered over

I've created navigation menu for my website. Here's the html: (you can also view the sidebar menu at belairfinishing.com, its the menu on the left.)
<div><img src="../public/images/skystatic.jpg" id="LinkForBannerImage"></div>
<ul>
<li>Proccess Technology</li>
<li>Equipment</li>
<li>Media & Compounds</li>
<li>Parts Cleaners & Dryers</li>
<li>Waste Water Treatment</li>
<li>Precious Metal Recovery</li>
<li>Consulting</li>
<li>Technical Articles</li>
<li>Press Releases</li>
<li>Toolhoning.com</li>
<li>Distributor Log In </li>
</ul>
</div>
Basically what I would like to happen is that when you hover over one of the items, ONLY the items directly before an after that get a red border. So if someone were to hover over Consulting, then Technical Articles and Precious Metal Recovery will have red borders.
I've been looking this up all morning and haven't found anything that works. So far I've tried to use nth-child(-n) and nth-child(n) to get 1 above an 1 below but I can't get that to actually work. Am I messing up the syntax or is their a better solution for this problem?
Thanks for the help!
Using CSS you could only select the next element using the adjacent sibling selector(+), however CSS doesn't have a previous sibling selector.
This could be achieve using jQuery.
$('li').hover(
function() {
$(this).next().find('a').addClass('highlight');
$(this).prev().find('a').addClass('highlight');
},
function() {
$(this).next().find('a').removeClass('highlight');
$(this).prev().find('a').removeClass('highlight')
})
#cssmenu {
text-align: center;
}
ul {
padding: 0;
list-style: none;
white-space: nowrap;
}
li {
display: inline-block;
vertical-align: top;
}
a {
display: block;
text-decoration: none;
width: 130px;
height: 50px;
line-height: 50px;
color: white;
background: #222;
box-sizing: border-box;
}
a:hover {
color: rosybrown;
}
.highlight {
border-bottom: 4px solid rosybrown;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cssmenu">
<ul>
<li class="active">Home</li
><li>About Us</li
><li>Contact Us</li
><li>Trade Shows</li
><li>Vibratory Workshops</li
><li class="last">Directions</li>
</ul>
</div>
Edit
You could also make it work using CSS alone.
The idea is to add a :before :pseudo-element to a on :hover, if the a is not a descendant of first li and :after :pseudo-element, if the a is not a descendant of the last li.
i.e, li:not(:first-child) a:hover:before, li:not(:last-child) a:hover:after.
In simple words, it won't add the line on the left if the li is the first element and won't add the line on the right if the li is the last element.
body {
margin: 0;
}
#cssmenu {
text-align: center;
margin: 0;
}
ul {
padding: 0;
margin: 0;
list-style: none;
white-space: nowrap;
}
li {
display: inline-block;
vertical-align: top;
}
a {
position: relative;
display: block;
text-decoration: none;
width: 130px;
height: 50px;
line-height: 50px;
color: white;
background: #222;
box-sizing: border-box;
}
a:hover {
color: rosybrown;
}
li:not(:first-child) a:hover:before, li:not(:last-child) a:hover:after {
content: '';
position: absolute;
width: 100%;
height: 4px;
left: -100%;
bottom: 0;
border-bottom: 4px solid rosybrown;
box-sizing: border-box;
}
li:not(:last-child) a:hover:after {
left: 100%;
z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cssmenu">
<ul>
<li class="active">Home</li
><li>About Us</li
><li>Contact Us</li
><li>Trade Shows</li
><li>Vibratory Workshops</li
><li class="last">Directions</li>
</ul>
</div>