When I place the cursor over the navigation item, the submenu appears, then when I move the mouse to click on something in the submenu, the submenu disappears.
I read a few similar issues on stackoverflow like changing z-index, didn't work for me
* {
font-family: arial, sans-serif;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
.nav {
position: fixed;
top: 0;
left: 0;
background-color: rgba(255, 255, 255, .8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 25px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
top: 107px;
padding: 10px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: space-evenly;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-evenly;
padding: 10;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255, 255, 255, .8);
}
ul {
list-style: none;
padding: 0;
}
<nav>
<ul class="nav">
<li class="item">
<a href="../index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" />
</a>
</li>
<li class="item has-children" style="color:#4D4D4D;">Printing
<ul class="submenu">
<li>Labels & Stickers</li>
<li>Banners</li>
<li>A-Frame</li>
<li>Menu Boards</li>
<li>Takeout Menus</li>
<li>Business Cards</li>
<li>Dine-In Menus</li>
<li>Posters</li>
<li>Envelopes</li>
<li>Chinese Wedding Cards</li>
<li>Flyers</li>
<li>Letterheads</li>
<li>Brochures</li>
<li>Vinyl</li>
<li>NCR Forms</li>
<li>Catalogues</li>
</ul>
</li>
<li class="item has-children">Graphic Design
<ul class="submenu">
<li>Logo Design</li>
<li>Ads/Flyers/Promotions</li>
<li style="text-align: center;">Menu Boards<br> (Digital & Boards)</li>
<li style="text-align: center;">Restaurant Menus<br> (Takeout & Dine-In)</li>
</ul>
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet Calendars</li>
<li>More Calendars</li>
<li></li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</nav>
When I place the cursor over the nav items, it should remain showing the submenu until I move the cursor of the nav flex item
The issue is that you have a top value on your .submenu class. This creates a gap where you are not technically "hovering" over the menu or submenu. The best way to fix this would be to use padding instead of top to push the submenu lower, while still having it technically cover the empty space.
Example:
* {
font-family: arial, sans-serif;
box-sizing: border-box;}
html, body {
margin: 0;
padding: 0;
}
.nav {
background-color: #ccc;
position:fixed;
top:0;
left:0;
/*background-color: rgba(255,255,255,.8);*/
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
/*padding: 25px 0;*/
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
display: flex;
align-items: center;
height: 100%;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
top: 100%;
padding: 10px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: space-evenly;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-evenly;
padding: 10;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255,255,255,.8);
}
ul {
list-style: none;
padding: 0;
height: 100px;
}
<nav>
<ul class="nav">
<li class="item">
<a href="../index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" />
</a>
</li>
<li class="item has-children" style="color:#4D4D4D;">Printing
<ul class="submenu">
<li>Labels & Stickers</li>
<li>Banners</li>
<li>A-Frame</li>
<li>Menu Boards</li>
<li>Takeout Menus</li>
<li>Business Cards</li>
<li>Dine-In Menus</li>
<li>Posters</li>
<li>Envelopes</li>
<li>Chinese Wedding Cards</li>
<li>Flyers</li>
<li>Letterheads</li>
<li>Brochures</li>
<li>Vinyl</li>
<li>NCR Forms</li>
<li>Catalogues</li>
</ul>
</li>
<li class="item has-children">Graphic Design
<ul class="submenu">
<li>Logo Design</li>
<li>Ads/Flyers/Promotions</li>
<li style="text-align: center;">Menu Boards<br>
(Digital & Boards)</li>
<li style="text-align: center;">Restaurant Menus<br>
(Takeout & Dine-In)</li>
</ul>
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet Calendars</li>
<li>More Calendars</li>
<li></li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</nav>
Related
I just noticed that having justify-content: space-evenly; spaces items from the middle, so items that are longer than another, create an uneven space between the items.
I tried space-around, which I assumed should solve it, but same issue.
nav {
position: sticky;
position: -webkit-sticky;
top: 0;
text-align: center;
width: 100%;
background-color: rgba(255, 255, 255, .8);
}
.nav {
position: sticky;
left: 0;
border-radius: 0px;
border: none;
margin-right: 10%;
margin-left: 10%;
width: 80%;
text-align: center;
padding: 0;
flex-direction: row;
display: flex;
align-items: center;
align-content: center;
justify-content: space-evenly;
cursor: default;
}
#media screen and (max-width: 1000px) {
.nav {
position: sticky;
left: 0;
border-radius: 0px;
border: none;
margin: auto;
width: 100%;
text-align: center;
padding: 0;
flex-direction: row;
display: flex;
align-items: center;
align-content: center;
justify-content: space-evenly;
}
}
<nav>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="../Images/Navigation/Intak Nav Mark.png" alt="Home" />
</a>
</li>
<li class="item" style="color:#4D4D4D;">Printing
</li>
<li class="item">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Lucky Money Envelopes</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">Contact Us</li>
</ul>
</nav>
I'm trying to get the items to have an even gap between them, regardless of length of item
This should solve it
justify-content:space-between;
I'm trying to set the logo to the left and the rest of the list to the right.
I tried removing it from the and adding it on it's own. it ends up behind the text even with a z-index= 2.
I tried a and floated it to the left i found in another thread. still didn't work
* {
font-family: arial, sans-serif;
box-sizing: border-box;}
html, body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
.nav {
position: fixed;
top: 0;
left: 0;
background-color: rgba(255,255,255,.8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 25px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: flex-end;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
font-size: 15px;
margin-left: 30px;
margin-right: 30px;
}
<nav>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" align="left"/>
</a>
</li>
<li class="item has-children" style="color:#4D4D4D;">Printing
</li>
<li class="item has-children">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</nav>
Need to some how split the logo from the nav and have it floated or positioned to the left
It appears that you'll want to separate out your home link from your navigation ul. Then make the <nav> element (to which I've assigned the class .nav-wrapper) a flex parent with justify-content property set to space-between. This will push the two elements (your <a> and your <ul>) to the left and right of their parent, respectively.
Then you can flex the <ul> itself so that its children (the <li>'s) arrange themselves in a neat horizontal row.
See below. You'll need to style this to your liking, but hopefully this will put you on the right path.
* {
font-family: arial, sans-serif;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
display: block;
}
.nav-wrapper {
width: 100%;
position: fixed;
display: flex;
align-items: center;
justify-content: space-between;
}
.nav {
margin-left: auto;
background-color: rgba(255, 255, 255, .8);
border-radius: 0px;
border: none;
margin: 0;
padding: 0;
display: flex;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
font-size: 15px;
margin-left: 30px;
margin-right: 30px;
}
<nav class="nav-wrapper">
<a href="index.html">
<img src="http://placehold.it/64x64" alt="Home" align="left" />
</a>
<ul class="nav">
<li class="item has-children" style="color:#4D4D4D;">Printing
</li>
<li class="item has-children">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</nav>
You should group all the other elements in a container, in the code below I've used another un order list. This way you can position the logo on one side and the other navigation elements on the other.
* {
font-family: arial, sans-serif;
box-sizing: border-box;}
html, body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
.nav {
position: fixed;
top: 0;
left: 0;
background-color: rgba(255,255,255,.8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 25px 0;
flex-direction: row;
display: flex;
justify-content: space-between;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
font-size: 15px;
margin-left: 30px;
margin-right: 30px;
}
.inner-nav {
display: flex;
}
<nav>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" align="left"/>
</a>
</li>
<li>
<ul class="inner-nav">
<li class="item has-children" style="color:#4D4D4D;">Printing
</li>
<li class="item has-children">Graphic Design
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Red Packet</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</li>
</ul>
</nav>
The items are evenly spaced to flex containers in all menus except the Chinese calendars tab, I don't understand why.
They were aligned perfectly, but when I added links to the submenu items, it spread out randomly. I'm almost certain I have to add something in a{} to correct this, but I've tried the following, but no fix:
Tried erasing the links. No fix.
Tried copying the code from the submenu into a{} in CSS, worsens the problem.
* {
font-family: arial, sans-serif;
box-sizing: border-box;}
html, body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
.nav {
position:fixed;
top:0;
left:0;
background-color: rgba(255,255,255,.8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 25px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
}
.submenu {
display: none;
flex-wrap: wrap;
align-items: center;
align-text: center;
position: absolute;
padding-top: 107px;
padding: 10px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: space-evenly;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-evenly;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255,255,255,.8);
}
ul {
list-style: none;
padding: 0;
}
<nav>
<ul class="nav">
<li class="item">
<a href="../index.html">
<img src="../Images/Navigation/Intak Logo 25px High.png" alt="Home" />
</a>
</li>
<li class="item has-children" style="color:#4D4D4D;">Printing
<ul class="submenu">
<li>Labels & Stickers</li>
<li>Banners</li>
<li>A-Frame</li>
<li>Menu Boards</li>
<li>Takeout Menus</li>
<li>Business Cards</li>
<li>Dine-In Menus</li>
<li>Posters</li>
<li>Envelopes</li>
<li>Chinese Wedding Cards</li>
<li>Flyers</li>
<li>Letterheads</li>
<li>Brochures</li>
<li>Vinyl</li>
<li>NCR Forms</li>
<li>Catalogues</li>
</ul>
</li>
<li class="item has-children">Graphic Design
<ul class="submenu">
<li>Logo Design</li>
<li>Ads/Flyers/Promotions</li>
<li style="text-align: center;">Menu Boards<br>
(Digital & Boards)</li>
<li style="text-align: center;">Restaurant Menus<br>
(Takeout & Dine-In)</li>
</ul>
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Packet Calendars</li>
<li>More Calendars</li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</nav>
Expected results is all nav submenu items to be aligned
You just have to change justify-content: space-evenly; to justify-content: left; for the .item.has-children:hover .submenu style.
The submenu style should be like this:
.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: left;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255,255,255,.8);
}
As for the Chinese Calendar's submenu, there are only 7 items, which cause it to have 4 on the first row and 3 on the second row, thus causing them to look like they're not aligned because the space-evenly style cause them to be centered with even space.
It isn't related to the links.
By setting them to left, it will prevent the white space on the left messing up with the position of the 2nd row.
Before and after (with red border visualizing the boxes)
justify-content: space-evenly;
justify-content: left;
The nav bar and submenu are perfectly aligned when the view port is full width of the screen. However, when I get to 720px where the nav item "Chinese Calendars" becomes two lines, it creates a gap between the nav bar and the submenu drop down.
I've tried shifting code around and removing things, but can't figure it out. I tried float: right;, creates an overlap instead of falling right below.
* {
font-family: arial, sans-serif;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: black;
}
nav {
position: sticky;
position: -webkit-sticky;
top: 0;
}
.nav {
position: sticky;
left: 0;
background-color: rgba(255, 255, 255, .8);
border-radius: 0px;
border: none;
width: 100%;
padding: 10px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: capitalize;
width: 25%;
text-align: center;
}
.submenu {
display: none;
flex-wrap: wrap;
margin-top: 29px;
align-items: center;
align-text: center;
position: absolute;
padding: 10px;
font-size: small;
left: 0;
right: 0;
text-transform: capitalize;
z-index: 1;
background-color: #2F4F4F;
color: white;
justify-content: left;
}
.submenu li {
margin-left: 6%;
width: 19%;
padding: 5px;
}
.submenuActive {
display: flex;
cursor: pointer;
align-items: center;
flex-direction: row;
justify-content: left;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255, 255, 255, .9);
}
/*.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: left;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255,255,255,.8);
}*/
ul {
list-style: none;
padding: 0;
}
.logo {
display: block;
margin-top: 50px;
margin-bottom: 25px;
}
.logo img {
display: block;
margin: auto;
max-width: 70%;
}
<a class="logo" href="index.html">
<img src="../../Images/Navigation/Intak Logo 40px High.png" alt="Home" />
</a>
<nav>
<ul class="nav">
<li class="item">
<a href="../index.html">
<img src="../../Images/Navigation/Intak Nav Mark -01.png" alt="Home" />
</a>
</li>
<li class="item has-children">Printing
<!-- <ul class="submenu">
<li>Labels & Stickers</li>
<li>Banners</li>
<li>A-Frame</li>
<li>Menu Boards</li>
<li>Takeout Menus</li>
<li>Business Cards</li>
<li>Dine-In Menus</li>
<li>Posters</li>
<li>Envelopes</li>
<li>Chinese Wedding Cards</li>
<li>Flyers</li>
<li>Letterheads</li>
<li>Brochures</li>
<li>Vinyl</li>
<li>NCR Forms</li>
<li>Catalogues</li>
</ul> -->
</li>
<li class="item has-children">Graphic Design
<!-- <ul class="submenu">
<li>Logo Design</li>
<li>Ads/Flyers/Promotions</li>
<li style="text-align: center;">Menu Boards<br>
(Digital & Boards)</li>
<li style="text-align: center;">Restaurant Menus<br>
(Takeout & Dine-In)</li>
</ul>-->
</li>
<li class="item has-children" style="color:#4D4D4D;">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll Calendars</li>
<li>Wall Calendars</li>
<li>Mini Calendars</li>
<li>Desk Calendars</li>
<li>Special Desk Calendars</li>
<li>Lucky Money Envelopes</li>
<li>More Calendars</li>
</ul>
</li>
<!-- <li class="item">FAQS</li> -->
<li class="item">Contact Us</li>
</ul>
</nav>
I need it so regardless of viewport size, the submenu is always touching the navigation bar
https://jsfiddle.net/nqjv3xs5/1/#&togetherjs=lgy6QvwL4g
Greater than 720px:
Less than 720px:
My main navigation item has a lot of child items, but I want to keep them visually appealing and clean. I'm trying to limit 4 submenu items per row.
I've checked other posts online, and their solution includes adding a flex: 1 1 25%;, I've tried this, but nothing changes.
.nav {
position: fixed;
top: 0;
left: 0;
background-color: rgba(255, 255, 255, .8);
border-radius: 0px;
border: none;
width: 100%;
margin: 0;
padding: 25px 0;
flex-direction: row;
display: flex;
align-items: center;
justify-content: space-evenly;
}
.item {
color: black;
font-weight: bold;
text-transform: uppercase;
}
.submenu {
display: none;
align-items: center;
align-text: center;
position: absolute;
top: 107px;
left: 0;
right: 0;
text-transform: uppercase;
z-index: 1;
background-color: #2F4F4F;
color: white;
}
.item.has-children:hover .submenu {
display: flex;
align-items: center;
flex-direction: row;
justify-content: space-evenly;
padding: 10;
flex-wrap: wrap;
flex: 1 1 calc(25% - 80px);
color: black;
background-color: rgba(255, 255, 255, .8);
}
<nav>
<ul class="nav">
<li class="item">
<a href="index.html">
<img src="Images/Navigation/Intak Logo 25px High.png" alt="Home" />
</a>
</li>
<li class="item has-children" style="color:#4D4D4D;">Printing
<ul class="submenu">
<li>Labels & Stickers</li>
<li>Banners</li>
<li>A-Frame</li>
<li>Menu Boards</li>
<li>Takeout Menus</li>
<li>Business Cards</li>
<li>Dine-In Menus</li>
<li>Posters</li>
<li>Envelopes</li>
<li>Chinese Wedding Cards</li>
<li>Flyers</li>
<li>Letterheads</li>
<li>Brochures</li>
<li>Vinyl</li>
<li>NCR Forms</li>
<li>Catalogues</li>
</ul>
</li>
<li class="item has-children">Graphic Design
<ul class="submenu">
<li>Logo Design</li>
<li>Ads/Flyers/Promotions</li>
<li>Menu Boards (Digital & Boards)</li>
<li>Menus (Takeout & Dine-In)</li>
</ul>
</li>
<li class="item has-children">Chinese Calendars
<ul class="submenu">
<li>Cane Wallscroll</li>
<li>Wall</li>
<li>Mini</li>
<li>Desk</li>
<li>Special Desk</li>
<li>Red Packet</li>
<li>More</li>
<li></li>
</ul>
</li>
<li class="item">FAQS</li>
<li class="item">Contact Us</li>
</ul>
</nav>
```
I expect it to form:
1 2 3 4
5 6 7 8
9 10 11 12
but stays: 12345678
Try adding flex-wrap to your .submenu and a width of 25% to your li items.
.submenu {
...
flex-wrap: wrap;
}
.submenu li {
width: 25%;
}
Example: https://codepen.io/giumagnani/pen/QPEjxp