Horizontal nav with horizontal submenu - vanishing underline - html

I have been asked to make horizontal navbar with a horizontal submenu as well. This behaves differently than the typical navbar, and the main issue I cannot solve is when I hover an item in the nav, it underlines and displays the submenu correctly. When I move the cursor to the submenu though, the underline disappears. I cannot figure out how to keep it underlined while mousing about the submenu.
HTML:
<!-- Beginning of Header -->
<div class='menu-container'>
<div class='menu'>
<div class='logo'>
<img
src="/images/logo.svg"
alt="Pershing's Own"
height="100"
width="150" />
</div>
<div class='calendar'>Calendar</div>
<div class='feedback'>Give Feedback</div>
<div class='tickets'><a class='red-button' href='https://www.eventbrite.com/o/the-us-army-band-pershings-own-2494510190'>Tickets</a></div>
</div>
</div>
<div class='header-container'>
<nav class='nav-container' role='navigation'>
<ul class='nav-menu'>
<li class='dropdown' tabindex='-1'>
Concerts & Events
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/event-page/event-page.html'>Concerts</a></li>
<li><a href='#'>Special Events</a></li>
<li><a href='#'>Twilight Tattoo</a></li>
<li><a href='#'>Workshops</a></li>
</ul> <!-- End of submenu -->
</li>
<li class='dropdown' tabindex='-1'>
Vacancies
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Current Openings</a></li>
<li><a href='#'>Conducting</a></li>
<li><a href='#'>Other Army Opportunities</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Watch & Listen
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Live Webcasts</a></li>
<li><a href='#'>YouTube Channel</a></li>
<li><a href='#'>Recordings</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Meet the Band
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/meet-the-band/soldiers.html'>Musicians</a></li>
<li><a href='/meet-the-band/ensembles.html'>Ensembles</a></li>
<li><a href='#'>Support Staff</a></li>
<li><a href='#'>Command Staff</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Engagement
<ul class='red-submenu'>
<li><a href='#'>Workshops</a></li>
<li><a href='#'>Competitions</a></li>
<li><a href='#'>Educational Outreach</a></li>
</ul>
</li>
</ul>
</nav>
</div>
<!-- End of Header -->
CSS:
body {
width: 1200px;
margin: 0 auto;
}
.nav-container {
color: #0C275B;
display: flex;
font-weight: 700;
justify-content: center;
}
nav {
width: 100%;
height: 75px;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-menu {
display: flex;
align-self: flex-end;
margin-bottom: 0px;
padding-left: 180px;
justify-content: space-evenly;
text-transform: uppercase;
font-size: 0.9em;
width: inherit;
}
.nav-menu a:link {
text-decoration: none;
color: #0C275B;
}
.nav-menu a:visited {
text-decoration: none;
color: #0C275B;
}
.nav-menu li {
display: inline;
padding-left: 0;
}
.nav-menu:focus {
pointer-events:none;
}
.dropdown a {
text-decoration: none;
font-size: 1em;
position: relative;
transition: all 0.6s;
}
.dropdown a:after {
content: '';
width: 0;
height: 0.3em;
position: absolute;
bottom: -5px;
left: 50%;
background: #0C275B;
transition: all 0.5s;
}
.dropdown a:hover:after {
width: 100%;
left: 0;
background: #C31F3C;
}
.red-submenu {
padding-left: 25%;
visibility: hidden;
opacity: 0;
position: absolute;
transition: all 0.5s ease;
border-top: solid white 0.5rem;
left: 0;
text-transform: none;
}
.red-submenu li {
padding-left: 80px;
}
.dropdown:active .red-submenu,
.dropdown:focus .red-submenu,
.dropdown:hover > .red-submenu,
.red-submenu:hover {
visibility: visible;
opacity: 1;
background-color: #C31F3C;
display: block;
width: 100%;
}
ul li ul li {
clear: both;
width: 100%;
}
.red-submenu a:link {
text-decoration: none;
color: #FFF;
}
.red-submenu a:visited {
text-decoration: none;
color: #FFF;
}
.red-submenu li a:hover:after {
width: 0%;
background: #C31F3C;
}
body {
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-style: normal;
font-weight: 300;
line-height: 1.8em;
color: #0C275B;
}
.menu-container {
color: #0C275B;
padding: 20px 0;
display: flex;
justify-content: center;
height: 60px;
}
.menu {
width: 100%;
display: flex;
justify-content: space-between;
font-size: 0.9em;
font-weight: 700;
}
.calendar {
margin-left: auto;
}
.feedback,
.tickets {
margin-left: 20px;
}
.tickets {
padding-right: 20px;
}
a.red-button {
color: #FFF;
background-color: #C31F3C;
font-family: 'Raleway', sans-serif;
font-weight: 700;
padding: 5px 10px 5px 10px;
height: 2.1em;
text-align: center;
border-radius: 10px;
text-decoration: none;
}
.logo {
width: 150px;
display: flex;
padding-left: 20px;
justify-content: flex-start;
}
I created a codepen here.
Menu has no JS - only HTML and CSS. If JS would solve this, that would be fine, but if there's a way to do it with just HTML and CSS, that would be preferable.

You should put the :hover on the li.dropdown element. So replace .dropdown a:hover:after with .dropdown:hover > a::after.
// Before
.dropdown a:hover:after {
width: 100%;
left: 0;
background: #C31F3C;
}
// After
.dropdown:hover > a::after {
width: 100%;
left: 0;
background: #C31F3C;
}
body {
width: 1200px;
margin: 0 auto;
}
.nav-container {
color: #0C275B;
display: flex;
font-weight: 700;
justify-content: center;
}
nav {
width: 100%;
height: 75px;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-menu {
display: flex;
align-self: flex-end;
margin-bottom: 0px;
padding-left: 180px;
justify-content: space-evenly;
text-transform: uppercase;
font-size: 0.9em;
width: inherit;
}
.nav-menu a:link {
text-decoration: none;
color: #0C275B;
}
.nav-menu a:visited {
text-decoration: none;
color: #0C275B;
}
.nav-menu li {
display: inline;
padding-left: 0;
}
.nav-menu:focus {
pointer-events:none;
}
.dropdown a {
text-decoration: none;
font-size: 1em;
position: relative;
transition: all 0.6s;
}
.dropdown a:after {
content: '';
width: 0;
height: 0.3em;
position: absolute;
bottom: -5px;
left: 50%;
background: #0C275B;
transition: all 0.5s;
}
.dropdown:hover > a::after {
width: 100%;
left: 0;
background: #C31F3C;
}
.red-submenu {
padding-left: 25%;
visibility: hidden;
opacity: 0;
position: absolute;
transition: all 0.5s ease;
border-top: solid white 0.5rem;
left: 0;
text-transform: none;
}
.red-submenu li {
padding-left: 80px;
}
.dropdown:active .red-submenu,
.dropdown:focus .red-submenu,
.dropdown:hover > .red-submenu,
.red-submenu:hover {
visibility: visible;
opacity: 1;
background-color: #C31F3C;
display: block;
width: 100%;
}
ul li ul li {
clear: both;
width: 100%;
}
.red-submenu a:link {
text-decoration: none;
color: #FFF;
}
.red-submenu a:visited {
text-decoration: none;
color: #FFF;
}
.red-submenu li a:hover:after {
width: 0%;
background: #C31F3C;
}
body {
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-style: normal;
font-weight: 300;
line-height: 1.8em;
color: #0C275B;
}
.menu-container {
color: #0C275B;
padding: 20px 0;
display: flex;
justify-content: center;
height: 60px;
}
.menu {
width: 100%;
display: flex;
justify-content: space-between;
font-size: 0.9em;
font-weight: 700;
}
.calendar {
margin-left: auto;
}
.feedback,
.tickets {
margin-left: 20px;
}
.tickets {
padding-right: 20px;
}
a.red-button {
color: #FFF;
background-color: #C31F3C;
font-family: 'Raleway', sans-serif;
font-weight: 700;
padding: 5px 10px 5px 10px;
height: 2.1em;
text-align: center;
border-radius: 10px;
text-decoration: none;
}
.logo {
width: 150px;
display: flex;
padding-left: 20px;
justify-content: flex-start;
}
<!-- Beginning of Header -->
<div class='menu-container'>
<div class='menu'>
<div class='logo'>
<img
src="/images/logo.svg"
alt="Pershing's Own"
height="100"
width="150" />
</div>
<div class='calendar'>Calendar</div>
<div class='feedback'>Give Feedback</div>
<div class='tickets'><a class='red-button' href='https://www.eventbrite.com/o/the-us-army-band-pershings-own-2494510190'>Tickets</a></div>
</div>
</div>
<div class='header-container'>
<nav class='nav-container' role='navigation'>
<ul class='nav-menu'>
<li class='dropdown' tabindex='-1'>
Concerts & Events
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/event-page/event-page.html'>Concerts</a></li>
<li><a href='#'>Special Events</a></li>
<li><a href='#'>Twilight Tattoo</a></li>
<li><a href='#'>Workshops</a></li>
</ul> <!-- End of submenu -->
</li>
<li class='dropdown' tabindex='-1'>
Vacancies
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Current Openings</a></li>
<li><a href='#'>Conducting</a></li>
<li><a href='#'>Other Army Opportunities</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Watch & Listen
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Live Webcasts</a></li>
<li><a href='#'>YouTube Channel</a></li>
<li><a href='#'>Recordings</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Meet the Band
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/meet-the-band/soldiers.html'>Musicians</a></li>
<li><a href='/meet-the-band/ensembles.html'>Ensembles</a></li>
<li><a href='#'>Support Staff</a></li>
<li><a href='#'>Command Staff</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Engagement
<ul class='red-submenu'>
<li><a href='#'>Workshops</a></li>
<li><a href='#'>Competitions</a></li>
<li><a href='#'>Educational Outreach</a></li>
</ul>
</li>
</ul>
</nav>
</div>
<!-- End of Header -->
<!-- Begin main section -->
<div class='main-container'>
</div>

Related

How to nest a submenu in mobile navigation hamburger menu?

I am trying to nest a submenu in a main menu for a mobile navigation hamburger menu. Here is an image of what I am trying to achieve:
Right now, my submenus are appearing over my other menus and not embedding inside. I cannot figure what I am doing wrong. Any help would be greatly appreciated!
Here is a link to the codepen.io pin.
Here is the same code in codepen.io:
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#100;300;400;500;700;900&display=swap');
* {
font-family: 'Roboto', sans-serif;
}
.main-navigation-bar {
height: 94px;
background-color: #00000000;
display: flex;
}
.section-1 {
width: 30%;
display: flex;
align-items: center;
}
.logo-box {
width: 208px;
height: 48px;
}
.section-2 {
width: 70%;
justify-content: flex-end;
margin-left: auto;
margin-right: 0;
flex-wrap: wrap;
display: flex;
}
.main-nav {
list-style-type: none;
overflow: hidden;
display: block;
}
.main-nav li{
float: left;
padding: 10px 20px 10px 20px;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
font-style: normal;
text-decoration: none;
line-height: 24px;
letter-spacing: .75px;
color: #1e1e1e;
}
.main-nav li:hover {
color: #1e1e1e75;
cursor: pointer;
transition: .4s;
}
.dropdown-content {
display: none;
position: absolute;
z-index: 1;
transform: translateX(calc(-50%));
max-width: 1000px;
margin-top: 10px;
}
.dropdown:hover .dropdown-content {
display: block;
}
.sub-menu {
list-style-type:none;
overflow:hidden;
display: flex;
box-shadow: 0px 0px 2px 0px rgb(30 30 30 / 25%) !important;
z-index: 3px;
border-radius: 8px;
width: 100%;
}
.sub-menu li {
float: left;
padding: 24px 32px !important;
width: 100%;
}
.sub-menu li:hover {
cursor: pointer;
}
.item1 {
border-right: 1px solid #f2f2f2;
}
.product {
display: block;
font-size: 20px;
font-weight: 700px;
color: #1e1e1e;
}
.tagline {
display: block;
font-size: 14px;
font-weight: 400;
line-height: 24px;
letter-spacing: .44px;
text-transform: none;
color: #1e1e1e;
}
.g4-sub-tabs {
list-style: none;
text-align: left;
padding-left: 0px;
}
.g4-sub-tabs li {
margin: 0px !important;
padding: 0px !important;
}
.li-sub-tab {
padding-left: 25px;
}
#check, .open-menu, .close-menu {
display: none;
}
#media only screen and (max-width: 959px) {
.open-menu, .close-menu {
position: absolute;
color: #1e1e1e;
cursor: pointer;
font-size: 1.5rem;
}
.open-menu {
right: 20px;
transform: translateY(-50%);
}
.close-menu {
top: 20px;
right: 20px;
}
#check {
display: none;
}
.main-navigation-bar {
height: 100vh;
display: block;
}
.section-2 {
width: 100%;
}
.mobile-menu {
flex-direction: column;
align-items: center;
justify-content: center;
}
.mobile-menu li {
width: 100%;
top: 0;
right: 0;
z-index: 100;
transition: all 0.2s ease-in-out;
}
.dropdown-content {
display: block;
position: absolute;
z-index: 1;
transform: translateX(calc(0%));
max-width: auto;
margin-top: 10px;
}
.sub-menu {
list-style-type:none;
overflow:hidden;
display: block;
box-shadow: 0px 0px 2px 0px rgb(30 30 30 / 25%) !important;
z-index: 0px;
border-radius: 8px;
width: 100%;
}
.sub-menu li {
float: left;
padding: 24px 32px !important;
width: 100%;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<header>
<div class="main-navigation-bar">
<div class="section-1">
<div class="logo-box">
<h1>Logo</h1>
</div>
</div>
<input type="checkbox" id="check">
<div class="section-2">
<nav>
<ul class="main-nav">
<span class="mobile-menu">
<span class="dropdown">
<li>Products
<span class="sub-arrow">
<i class="fas fa-chevron-down"></i>
</span></span>
<span class="dropdown-content">
<ul class="sub-menu">
<li class="item1 "><span class="product">1A</span><p class="tagline">Lorem ipsum solor sal</p>
<ul class="g4-sub-tabs">
<li>•<span class="li-sub-tab">Link</span></li>
<li>•<span class="li-sub-tab">Link</span></li><li>•<span class="li-sub-tab">Link</span></li>
</ul>
</li>
<li class"item2"><span class="product">1B</span><p class="tagline">lorem ipsum dolor sal</p></li>
</ul>
</span>
</li>
<li>Resources</li>
<li>Company</li>
<li>Careers</li>
<li>Contact Us</li>
<label for="check" class="close-menu"><i class="fas fa-times"></i></label>
</span>
<label for="check" class="open-menu"><i class="fas fa-bars"></i></label>
</ul>
</nav>
</div>
</div>
</header>
Simply use the CSS display rule and toggle none.
if (document.getElementById("btn")) {
document.getElementById("btn").addEventListener("click", function (evt) {
toggleDisplay(evt);
});
}
function toggleDisplay(evt){
document.getElementById("first").classList.toggle("hidden");
}
.hidden {
display: none;
}
<header>
<div class="main-navigation-bar">
<button id="btn">toggle me</button>
<div class="section-1">
<div class="logo-box">
<h1>Logo</h1>
</div>
</div>
<div class="section-2">
<nav>
<ul class="main-nav">
<span class="mobile-menu">
<span class="dropdown">
<li>Products
<span class="sub-arrow">
<i class="fas fa-chevron-down"></i>
</span></span>
<span class="dropdown-content">
<ul class="hidden" id="first">
<li class="item1 "><span class="product">1A</span><p class="tagline">Lorem ipsum solor sal</p>
<ul class="g4-sub-tabs">
<li>•<span class="li-sub-tab">Link</span></li>
<li>•<span class="li-sub-tab">Link</span></li><li>•<span class="li-sub-tab">Link</span></li>
</ul>
</li>
<li class"item2"><span class="product">1B</span><p class="tagline">lorem ipsum dolor sal</p></li>
</ul>
</span>
</li>
<li>Resources</li>
<li>Company</li>
<li>Careers</li>
<li>Contact Us</li>
<label for="check" class="close-menu"><i class="fas fa-times"></i></label>
</span>
<label for="check" class="open-menu"><i class="fas fa-bars"></i></label>
</ul>
</nav>
</div>
</div>
</header>

Why isn't the exit icon showing when menu is clicked

I have tried literally everything to try and make the exit icon show up on the menu by giving it an index of 999 but still no luck in making it show, any idea why it is not working?
I have added the JavaScript as well.
menuBtn.addEventListener('click' , () => {
const menu = document.querySelectorAll('.menu');
for(let el of menu){
el.style.display = 'block'
}
})
/*Navbar*/
.navbar {
width: 100%;
position: fixed;
font-family: "Ubuntu", sans-serif;
padding: 30px 0;
}
.navbar .logo a {
font-size: 2rem;
font-weight: 600;
color: white;
}
.navbar .logo a span {
color: crimson;
transition: all 0.3s ease;
}
.sticky {
padding: 30px 0;
background-color: crimson;
}
.sticky .logo a span {
color: #fff;
}
.menu li {
display: inline-block;
list-style: none;
}
.menu li a {
color: #fff;
font-size: 1.1rem;
font-weight: 500;
margin-left: 35px;
padding-left: 5px;
transition: color 0.3s ease;
}
.menu li a:hover {
border-left: 3px solid white;
color: crimson;
}
.sticky .menu li a:hover {
color: white;
}
.navbar .max-width {
display: flex;
align-items: center;
justify-content: space-between;
}
.max-width {
max-width: 1300px;
padding: 0 80px;
margin: auto;
}
/*Menu Button*/
.fa.fa-bars.menuBtn {
color: #fff;
font-size: 35px;
cursor: pointer;
display: none;
}
.fa.fa-times-circle.exit {
color: white;
font-size: 35px;
cursor: pointer;
display: none;
}
#media (max-width: 934px) {
.max-width {
padding: 0 50px;
}
.fa.fa-bars.menuBtn {
display: block;
padding-left: 10em;
}
.menu {
position: fixed;
height: 100vh;
width: 100%;
left: 0;
top: 0;
background-color: #111;
text-align: center;
padding-top: 110px;
display: none;
}
.fa.fa-times-circle.exit {
z-index: 999;
display: none;
margin: 1.8rem;
}
.menu ul li {
display: block;
}
.menu ul li a {
display: inline-block;
margin: 20px 0;
font-size: 35px;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#fortawesome/fontawesome-free#5.15.3/css/fontawesome.min.css" integrity="sha384-wESLQ85D6gbsF459vf1CiZ2+rr+CsxRY0RpiF1tLlQpDnAgg6rwdsUF1+Ics2bni" crossorigin="anonymous">
<header>
<nav class="navbar" id="nav">
<div class="max-width">
<div class="logo"><a id="headSpan" href="index.html">Port<span>folio.</span></a></div>
<div class="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Skills</li>
<li>Projects</li>
<li>CV</li>
<li>Contact</li>
</ul>
</div>
<div>
<i class="fa fa-bars menuBtn" id="menuBtn" aria-hidden="true"></i>
<i class="fa fa-times-circle exit" id="exitBtn" aria-hidden="true"></i>
</div>
</div>
</nav>
<!--Head Banner-->
<section class="home" id="home">
<div class="max-width">
<div class="home-content">
<div class="text-1">Hello, my name is</div>
<div class="text-2">Hadi Zouhbi</div>
<div class="text-3">And I'm a <span id="headSpan"><Developer></Developer></span></div>
</div>
</div>
</section>
</header>
Because it never made display:block when enter in small screen like you did for menubtn.
.fa.fa-bars.menuBtn {
display: block;
padding-left: 10em;
}
Do the same for exit icon under #media (max-width: 934px) also
.fa.fa-times-circle.exit {
display: inline-block;
}
And remove this code
.fa.fa-times-circle.exit {
z-index: 999;
display: none;
margin: 1.8rem;
}
Working example:
/*Navbar*/
body {
background-color: #ccc;
}
.navbar {
width: 100%;
position: fixed;
font-family: "Ubuntu", sans-serif;
padding: 30px 0;
}
.navbar .logo a {
font-size: 2rem;
font-weight: 600;
color: white;
}
.navbar .logo a span {
color: crimson;
transition: all 0.3s ease;
}
.sticky {
padding: 30px 0;
background-color: crimson;
}
.sticky .logo a span {
color: #fff;
}
.menu li {
display: inline-block;
list-style: none;
}
.menu li a {
color: #fff;
font-size: 1.1rem;
font-weight: 500;
margin-left: 35px;
padding-left: 5px;
transition: color 0.3s ease;
}
.menu li a:hover {
border-left: 3px solid white;
color: crimson;
}
.sticky .menu li a:hover {
color: white;
}
.navbar .max-width {
display: flex;
align-items: center;
justify-content: space-between;
}
.max-width {
max-width: 1300px;
padding: 0 80px;
margin: auto;
}
/*Menu Button*/
.fa.fa-bars.menuBtn {
color: #fff;
font-size: 35px;
cursor: pointer;
display: none;
}
.fa.fa-times-circle.exit {
color: white;
font-size: 35px;
cursor: pointer;
display: none;
}
#media (max-width: 934px) {
.max-width {
padding: 0 50px;
}
.fa.fa-bars.menuBtn {
display: block;
padding-left: 10em;
}
.fa.fa-times-circle.exit {
display: inline-block;
}
.menu {
position: fixed;
height: 100vh;
width: 100%;
left: 0;
top: 0;
background-color: #111;
text-align: center;
padding-top: 110px;
display: none;
}
.menu ul li {
display: block;
}
.menu ul li a {
display: inline-block;
margin: 20px 0;
font-size: 35px;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#fortawesome/fontawesome-free#5.15.3/css/fontawesome.min.css" integrity="sha384-wESLQ85D6gbsF459vf1CiZ2+rr+CsxRY0RpiF1tLlQpDnAgg6rwdsUF1+Ics2bni" crossorigin="anonymous">
<header>
<nav class="navbar" id="nav">
<div class="max-width">
<div class="logo"><a id="headSpan" href="index.html">Port<span>folio.</span></a></div>
<div class="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Skills</li>
<li>Projects</li>
<li>CV</li>
<li>Contact</li>
</ul>
</div>
<div>
<i class="fa fa-bars menuBtn" id="menuBtn" aria-hidden="true"></i>
<i class="fa fa-times-circle exit" id="exitBtn" aria-hidden="true"></i>
</div>
</div>
</nav>
<!--Head Banner-->
<section class="home" id="home">
<div class="max-width">
<div class="home-content">
<div class="text-1">Hello, my name is</div>
<div class="text-2">Hadi Zouhbi</div>
<div class="text-3">And I'm a <span id="headSpan"><Developer></Developer></span></div>
</div>
</div>
</section>
</header>

How do you make the box extend all the way till the end if when you hover

I am trying to get the box to extend all the to the end on both sides when i hover with things like flex but it wont work.
Ps i know i have the display block in there
#mainNav ul {
display: flex;
padding: 0px 0px 500px 0px;
list-style: none;
}
#mainNav li {
width: 100%;
position: relative;
text-align: center;
}
#mainNav a {
color: black;
text-decoration: none;
background-color: rgb(121, 184, 19);
display: flex;
justify-content: center;
height: 65px;
align-items: center;
font-size: 30px;
letter-spacing: 2px;
text-transform: uppercase;
font-weight: bold;
}
#mainNav a:hover {
background-color: rgb(196, 107, 5);
transition: .3s ease-in;
}
.secondUl {
display: flex;
flex-direction: column;
position: absolute;
width: 100%;
}
.secondUl li {
display: none;
position: absolute;
top: 0px;
}
#mainNav li:hover .secondUl>li {
display: block;
width: 100%;
top: 0px;
}
<nav id="mainNav">
<ul>
<li>Home</li>
<li>Carrot Shops nere me
<ul class="secondUl">
<li>Walmart</li>
<li>Target</li>
<li>Costco</li>
</ul>
</li>
<li>More
<ul class="secondUl">
<li>Biggest Carrot ever</li>
<li>Biggest carrot farm ever</li>
<li>Most carrots ate in 1 serveing</li>
</ul>
</li>
</ul>
</nav>
Hope it helps. Please let me know if you had wanted this.
#mainNav ul {
display: flex;
padding: 0px 0px 500px 0px;
list-style: none;
}
#mainNav li {
width: 100%;
position: relative;
text-align: center;
}
#mainNav a {
color: black;
text-decoration: none;
background-color: rgb(121, 184, 19);
display: flex;
justify-content: center;
height: 65px;
align-items: center;
font-size: 20px;
letter-spacing: 2px;
text-transform: uppercase;
font-weight: bold;
}
#mainNav a:hover {
background-color: rgb(196, 107, 5);
transition: .3s ease-in;
}
.secondUl {
display: flex;
flex-direction: column;
position: absolute;
width: 100%;
}
.secondUl li {
display: none;
position: absolute;
top: 0px;
}
#mainNav li:hover .secondUl>li {
display: block;
width: 100%;
top: 0px;
}
<link rel="stylesheet" type="text/css" href="style.css">
<nav id="mainNav">
<ul>
<li>Home</li>
<li>Carrot Shops nere me
<ul class="secondUl">
<li>Walmart</li>
<li>Target</li>
<li>Costco</li>
</ul>
</li>
<li>More
<ul class="secondUl">
<li>Biggest Carrot ever</li>
<li>Biggest carrot farm ever</li>
<li>Most carrots ate in 1 serveing</li>
</ul>
</li>
</ul>
</nav>

Split up li in navbar to different sides using flexbox

I'm trying to set up my navbar so I have the github and linkedin imgs/links on the left side, but I want to keep the bio/portfolio/contact links on the right.
I'm using flexbox on the nav, but I'm not sure if I can split up this ul such that the lis are on different sides.
I'm using flexbox on the nav, but I'm not sure if I can split up this ul such that the lis are on different sides since I have justify-content: space-between on.
I have no idea what I should change to make this work.
fiddle: https://jsfiddle.net/Ginsole/4svpeLq9/
nav {
background-color: #265B8B;
height:60px;
color: white;
position: fixed;
top:0;
left:0;
right:0;
width: 100%;
display: flex;
justify-content: space-between;
}
nav p {
font-weight: bold;
margin-left: 1em;
color: white;
text-align: left;
margin-top:1.25em;
font-size: 1em;
}
nav a {
color: white;
font-size: 1em;
font-weight: bold;
}
nav ul {
margin-bottom: 5em;
display: flex;
margin-top: 1.25em;
}
nav li {
list-style: none;
margin-right: 1em;
}
nav li.github {
margin-left: auto;
}
nav img {
width: 25px;
height: 25px;
margin-right: 10px;
}
.menu-toggle {
position: absolute;
padding: 0.8 em;
top: 1em;
right: 1em;
cursor: pointer;
}
<nav>
<p>STEVEN KANG</p>
<ul>
<li class="rightLinks"><a data-scroll-target="contact">Contact</a></li>
<li class="rightLinks"><a data-scroll-target="projects">Portfolio</a></li>
<li class="rightLinks"><a data-scroll-target="bio">Bio</a></li>
<li class="leftLinks"><img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"></li>
<li class="leftLinks"><img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/LinkedIn_logo_initials.png"></li>
</ul>
<div class="menu-toggle">
<i class="fa fa-bars"></i>
</div>
</nav>
I expect to have the two img links on the left and keep the rest of the links on the right side.
Here is updated version
https://jsfiddle.net/chille1987/236x0ntq/9/
nav {
background-color: #265B8B;
height:60px;
color: white;
position: fixed;
top:0;
left:0;
right:0;
width: 100%;
display: flex;
}
nav p {
font-weight: bold;
margin-left: 1em;
color: white;
text-align: left;
margin-top:1.25em;
font-size: 1em;
}
nav a {
color: white;
font-size: 1em;
font-weight: bold;
}
nav ul {
flex: 1;
margin-bottom: 5em;
display: flex;
flex-direction: row-reverse;
margin-top: 1.25em;
}
nav li {
list-style: none;
margin-right: 1em;
}
nav li.linkedin {
margin-right: auto;
}
nav img {
width: 25px;
height: 25px;
margin-right: 10px;
}
.menu-toggle {
position: absolute;
padding: 0.8 em;
top: 1em;
right: 1em;
cursor: pointer;
}
<nav>
<p>STEVEN KANG</p>
<ul>
<li class="rightLinks contact"><a data-scroll-target="contact">Contact</a></li>
<li class="rightLinks"><a data-scroll-target="projects">Portfolio</a></li>
<li class="rightLinks"><a data-scroll-target="bio">Bio</a></li>
<li class="leftLinks linkedin"><img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/LinkedIn_logo_initials.png"></li>
<li class="leftLinks github"><img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"></li>
</ul>
<div class="menu-toggle">
<i class="fa fa-bars"></i>
</div>
</nav>

Vertically center an HTML header

I can not seem to get my header to have the titles centered in the middle of the header box. How it looks now, it has the news, contacts, and about links high up in the box and not centered.
HTML:
<ul>
<li style="float:left"><a class="active" <a onclick="window.open(this.href, this.target);return false;" href="http://link/" target="link"> <img src="Logo.png" alt="Logo" style="width:125px;height:75px;"></a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
CSS:
ul {
list-style-type: none;
margin: 0;
padding: 10px;
overflow: hidden;
background-color: black;
}
li {
float: left;
}
li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: red;
}
.active {
background-color: black;
}
Try this on the <li>:
.li {
position: relative;
top: 50%;
transform: translateY(-50%);
}
how this works
EDIT: Cleaned up some unbalanced HTML issues and cleaned up the css:
ul {
list-style-type: none;
margin: 0;
padding: 50px; /* adjust as necessary */
overflow: hidden;
background-color: black;
}
li {
float: left;
position: relative;
top: 50%;
transform: translateY(-50%);
}
li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
<ul>
<li>
<a class="active" onclick="window.open(this.href, this.target);return false;" href="http://link/" target="link"> <img src="Logo.png" alt="Logo" style="width:125px;height:75px;"></a>
</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
here's a more modern approach:
https://jsfiddle.net/qq0t46pt/2/
flexbox is also well supported now, and easier to implement.
HTML
<ul>
<li style="float:left"><a class="active"> <a onclick="window.open(this.href, this.target);return false;" href="http://link/" target="link"> <img src="Logo.png" alt="Logo" style="width:125px;height:75px;"></a></a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
CSS
ul {
list-style-type: none;
margin: 0;
padding: 10px;
overflow: hidden;
background-color: black;
display: -webkit-flexbox;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
justify-content: center;
height: 370px;
}
li {
float: left;
}
li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: red;
}
.active {
background-color: black;
}