Adding 2nd level Dropdown Navbar to 1 level - html

<nav>
<ul>
<li>What is it?</li>
<li>
Inventory
<ul>
<li>
X-box 360
<ul>
<li>Building Blocks</li>
<li>Decorations</li>
<li>Redstone & Transportation</li>
<li>Materials</li>
<li>Food</li>
<li>Tools, Weapons & Armor</li>
<li>Brewing</li>
<li>Miscellaneous</li>
</ul>
</li>
<li>PC</li>
<ul>
<li>Building Blocks</li>
<li>Decoration Blocks</li>
<li>Redstone</li>
<li>Transportation</li>
<li>Miscellaneous</li>
<li>Foodstuff</li>
<li>Tools</li>
<li>Combat</li>
<li>Brewing</li>
<li>Materials</li>
</ul>
</li>
<li>Mobile</li>
<ul>
<li>Materials</li>
<li>Tools & Weapons</li>
<li>Decoration Blocks</li>
<li>Building Blocks</li>
</ul>
</li>
<li>PS4</li>
<ul>
<li>Building Blocks</li>
<li>Decorations</li>
<li>Redstone & Transportation</li>
<li>Materials</li>
<li>Food</li>
<li>Tools, Weapons & Armor</li>
<li>Brewing</li>
<li>Miscellaneous</li>
</ul>
</li>
</nav>
That's my code so far; it does a single level drop down but I tried to add a second level by doing the same thing I did to get the first drop down and it wont work. Its for a school project and I have researched how to add a second level but nothing I've tried has helped so far, so if you guys could give me any advice, or show me where I need to add thing to make it work I would love it. Thanks!

First you need fix your html code, there are several error in markup, can you check if this is the desired menu, notice in your code example that you are closing li element before open ul for each submenu, this is an error, ul need to be inside li and after ul you should close parent li.
a {
color: #FFF;
}
nav {
margin: 50px 0;
background-color: #E64A19;
}
nav ul {
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
display:inline-block;
background-color: #E64A19;
}
nav a {
display:block;
padding:0 10px;
color:#FFF;
font-size:20px;
line-height: 60px;
text-decoration:none;
}
nav a:hover {
background-color: #000000;
}
/* Hide Dropdowns by Default */
nav ul ul {
display: none;
position: absolute;
top: 60px; /* the height of the main nav */
}
/* Display Dropdowns on Hover */
nav ul li:hover > ul {
display:inherit;
}
/* Fisrt Tier Dropdown */
nav ul ul li {
width:170px;
float:none;
display:list-item;
position: relative;
}
/* Second, Third and more Tiers */
nav ul ul ul li {
position: relative;
top:-60px;
left:170px;
}
/* Change this in order to change the Dropdown symbol */
li > a:after { content: ' +'; }
li > a:only-child:after { content: ''; }
<nav>
<ul>
<li>What is it?</li>
<li>
Inventory
<ul>
<li>
X-box 360
<ul>
<li>Building Blocks</li>
<li>Decorations</li>
<li>Redstone & Transportation</li>
<li>Materials</li>
<li>Food</li>
<li>Tools, Weapons & Armor</li>
<li>Brewing</li>
<li>Miscellaneous</li>
</ul>
</li>
<li>
PC
<ul>
<li>Building Blocks</li>
<li>Decoration Blocks</li>
<li>Redstone</li>
<li>Transportation</li>
<li>Miscellaneous</li>
<li>Foodstuff</li>
<li>Tools</li>
<li>Combat</li>
<li>Brewing</li>
<li>Materials</li>
</ul>
</li>
<li>
Mobile
<ul>
<li>Materials</li>
<li>Tools &amp; Weapons</li>
<li>Decoration Blocks</li>
<li>Building Blocks</li>
</ul>
</li>
<li>
PS4
<ul>
<li>Building Blocks</li>
<li>Decorations</li>
<li>Redstone & Transportation</li>
<li>Materials</li>
<li>Food</li>
<li>Tools, Weapons & Armor</li>
<li>Brewing</li>
<li>Miscellaneous</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
If you don't need two first items then you need extract from the first ul to individual ul.
You will need a portion of css code to format this menu.
can you view and example here https://codepen.io/andornagy/pen/xhiJH

Related

Make nested list element show on mouseover

I'm trying to make a collapsible/expandable navigation bar menu. I have the right element targeted, but I can't get it to show the sub-menu on hover-over.
I'd like to keep the HTML as is, and not use any classes if possible, I'd like to learn the basics of doing this without classes, to attain a better understanding of what I'm doing, in manipulating HTML elements. The main point in doing this, is just to get comfortable with accessing elements.
ul {
list-style: none;
}
ul li a {
color: white;
display: none;
}
ul li:hover a {
display: block;
background-color: red;
}
ul ul li {
background-color: pink;
color: white;
}
ul ul li:hover ul a {
display: block;
background-color: purple;
}
<nav>
<ul>
<li>Music</li>
<ul>
<li>Songs</li>
<ul>
<li>Blue Slide Park</li>
<li>What's The Use</li>
<li>Hurt Feelings</li>
<li>Fight The Feeling</li>
</ul>
<li>Albums</li>
<ul>
<li>Blue Slide Park</li>
<li>WMWTSO</li>
<li>GO:OD AM</li>
<li>The Devine Feminine</li>
<li>Swimming</li>
</ul>
</ul>
<li>Videos</li>
<ul>
<li>Objects</li>
<li>Dang!</li>
<li>Weekend</li>
<li>Killin' Time</li>
<li>My Favorite Part</li>
<li>Best Day Ever</li>
</ul>
<li>About</li>
</ul>
</nav>
Your have a wrong structure of HTML markup.
Also, you should only handle the display of <ul> instead of <a> like this:
nav > ul ul {
display: none;
}
nav > ul > li:hover > ul,
nav > ul > li > ul > li:hover > ul {
display: block;
}
<nav>
<ul>
<li>Music
<ul>
<li>Songs
<ul>
<li>Blue Slide Park</li>
<li>What's The Use</li>
<li>Hurt Feelings</li>
<li>Fight The Feeling</li>
</ul>
</li>
<li>Albums
<ul>
<li>Blue Slide Park</li>
<li>WMWTSO</li>
<li>GO:OD AM</li>
<li>The Devine Feminine</li>
<li>Swimming</li>
</ul>
</li>
</ul>
</li>
<li>Videos
<ul>
<li>Objects</li>
<li>Dang!</li>
<li>Weekend</li>
<li>Killin' Time</li>
<li>My Favorite Part</li>
<li>Best Day Ever</li>
</ul>
</li>
<li>About</li>
</ul>
</nav>
Hope this helps you.

Why my menu doesn't work?

I have problem with the menu in my project in particular with the show him. I want when I hover the Tips for health, Recipes and inside of the last one the sub-menu of Salads, Fresh and Smoothies to show.
This is the HTML code:
`
<div id="nav">
<ul class="nav-list">
<li>Home</li>
<li>Tips for health</li>
<li>
<ul class="sub-nav-list">
<li>The healing properties</li>
<li>5 important spices that you should include in your diet</li>
<li>Bad habits and their removal</li>
<li>Water as a source of life</li>
</ul>
</li>
<li>Recipes</li>
<li>
<ul class="sub-nav-list">
<li><a href="#"Salads</a></li>
<li>Lettuce</li>
<li>French salad</li>
<li><a href="salata%20cherveno%20cveklo.html"Red Beet Salad</a></li>
</ul>
</li>
<li>
<ul class="sub-nav-list">
<li>Fresh</li>
<li>Sweet fresh</li>
<li>Fresh detox</li>
<li>Citrus fresh</li>
</ul>
</li>
<li>
<ul class="sub-nav-list">
<li>Smoothies</li>
<li>Смути шоколад</li>
<li>Chocolate smoothie</li>
<li>Smoothie with banana and pineapple</li>
</ul>
</li>
<li>Contacts</li>
</ul>
</div>
And this is the CSS code:
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #F6F2E8;
}
li a {
display: block;
color: #A6BB79;
padding: 8px 0 8px 16px;
text-decoration: none;
}
.sub-nav-list{
display: none;
}
ul.nav-list li > ul.sub-nav-list li a:hover {
color: red;
display: block;
}
Do you mean that when you hover a parent item '<li>Tips for health</li>' you want the sub navigation ul '<ul class="sub-nav-list"></ul>' to show?
If so you have a few things you need to change.
You need to rearrange your html so that the ul.sub-nav-list are within the parent li's
You need to target the ul.sub-nav-list rather than the li a's with the css to display them
For example;
<div id="nav">
<ul class="nav-list">
<li>Home</li>
<li>
Tips for health
<ul class="sub-nav-list">
<li>The healing properties</li>
<li>5 important spices that you should include in your diet</li>
<li>Bad habits and their removal</li>
<li>Water as a source of life</li>
</ul>
</li>
<li>
Recipes
<ul class="sub-nav-list">
<li><a href="#"Salads</a></li>
<li>Lettuce</li>
<li>French salad</li>
<li><a href="salata%20cherveno%20cveklo.html"Red Beet Salad</a></li>
</ul>
</li>
<li>
Fresh
<ul class="sub-nav-list">
<li>Sweet fresh</li>
<li>Fresh detox</li>
<li>Citrus fresh</li>
</ul>
</li>
<li>
<li>Smoothies<
<ul class="sub-nav-list">
<li>Смути шоколад</li>
<li>Chocolate smoothie</li>
<li>Smoothie with banana and pineapple</li>
</ul>
</li>
<li>Contacts</li>
</ul>
</div>
This now has the correct structure.
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #F6F2E8;
}
li a {
display: block;
color: #A6BB79;
padding: 8px 0 8px 16px;
text-decoration: none;
}
.sub-nav-list{
display: none;
}
ul.nav-list li:hover > ul.sub-nav-list {
color: red;
display: block;
}
This will display any ul that is a child of an li that is hovered

How to stop CSS/HTML last drop down menu going missing on smaller screens

first post on here but a regular reader and user for various problems. I have this bit of code here to make a drop down menu. I have also attached my CSS code for said menu. The menus are working great other than one part. My last drop down menu with id "workwear" continues to the left as it should, this is great for high res screens however, for smaller screens the user can't see half of the menu not visible on their screen. What I would like to happen is the drop down to align to the right hand side of the workwear link rather than the left and continue out to the right
I have tried giving the 'workwear' ul a class and trying various things in my CSS I have researched however nothing seems to work.
Go easy on me if this a basic error and I appreciate any help you can give me.
<div id="ProdBar">
<ul id="Prods">
<li><a id="BuildingSupplies" href="BuildingSupplies.php" title="Building Supplies"> <span>Building Supplies</span></a>
<ul>
<li>Cement, Mortar & Plaster</li>
<li>Drainage</li>
<li>Gutterings</li>
<li>Screws & Fixings</li>
<li>Silicones & Sealants</li>
<li>Adhesives & Pastes</li>
</ul>
</li>
<li><a id="DoorsSecurity" href="DoorsSecurity.php" title="Doors And Security"><span>Doors And Security</span></a>
<ul>
<li>Handles & Accessories</li>
<li>Door Locks</li>
<li>Padlocks</li>
</ul>
</li>
<li><a id="Electrics" href="Electrics.php" title="Electrics"><span>Electrics</span></a>
<ul>
<li>Bulbs & Strip Lighting</li>
<li>Extensions & Sockets</li>
<li>Outdoor Lighting</li>
<li>Switches</li>
<li>Wires & Cable</li>
</ul>
</li>
<li><a id="Flooring" href="Flooring.php" title="Flooring And Tiling"><span>Flooring & Tiling</span></a>
<ul>
<li>Grips & Fittings</li>
<li>Grouts & Adhesives</li>
</ul>
</li>
<li><a id="GardeningOutdoors" href="Gardening.php" title="Gardening And Outdoors"><span>Gardening & Outdoors</span></a>
<ul>
<li>Hoses & Fittings</li>
<li>Foods & Treatments</li>
<li>Lawn Care</li>
<li>Pest Control</li>
<li>Gardening Tools</li>
<li>Tool Consumables</li>
<li>Weedkillers & Cleaners</li>
<li>Exterior Woodcare</li>
</ul>
</li>
<li><a id="HandPowerTools" href="HandPowerTools.php" title="Hand And Power Tools"><span>Hand & Power Tools</span></a>
<ul>
<li>Drills</li>
<li>Grinders</li>
<li>Hand Tools</li>
<li>Power Tool Accessories</li>
<li>Sanders & Planers</li>
<li>Work Tables</li>
</ul>
</li>
<li><a id="Homewares" href="Homewares.php" title="Homewares"><span>Homewares</span></a>
<ul>
<li>Cleaning</li>
<li>Curtain Fixtures</li>
<li>Fireplace Products</li>
</ul>
</li>
<li><a id="PaintingDecorating" href="PaintingDecorating.php" title="Painting And Decorating"><span>Painting & Decorating</span></a>
<ul>
<li>Adhesives & Pastes</li>
<li>Decorating Tools</li>
<li>Emulsion</li>
<li>Exterior Paints</li>
<li>Filler & Caulk</li>
<li>Gloss, Satin & Undercoat</li>
<li>Silicone & Sealants</li>
<li>Specialist Paints</li>
<li>Steps & Ladders</li>
<li>Woodcare</li>
</ul>
</li>
<li><a id="Plumbing" href="Plumbing.php" title="Plumbing"><span>Plumbing</span></a>
<ul>
<li>Consumables</li>
<li>Pipes & Fittings</li>
<li>Plumbing Tools</li>
<li>Shower Fittings</li>
<li>Taps & Plugs</li>
<li>Toilet Accessories</li>
<li>Venting</li>
</ul>
</li>
<li><a id="Workwear" href="Workwear.php" title="Workwear"><span>Workwear</span></a>
<ul>
<li>Consumables</li>
<li>Coveralls</li>
<li>Ear & Eye Protection</li>
<li>Footwear</li>
<li>Jackets, Fleeces & Hoodies</li>
<li>Socks, Hats & Gloves</li>
<li>Trousers</li>
<li>T Shirts</li>
</ul>
</li>
</ul>
</div>
Here is my CSS
#Prods, #Prods ul {
padding: 0;
margin: 0;
list-style: none;
}
#Prods li {
float: left;
width: auto;
}
#Prods a {
display: block;
}
#Prods li ul {
position: absolute;
width: 200px;
left: -999em;
background:#C60001;
}
#Prods li ul.last {
width: 200px;
}
#Prods li:hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0;
}
#Prods li:hover li {
float: none;
font-family:"Century Gothic";
font-size:14px;
}
#Prods li:hover li a {
color: #FFF;
padding-top:6px;
padding-left:6px;
padding-bottom:6px;
text-decoration:none;
}
#Prods li li a:hover {
background-color: #FF0000;
color: #FFF;
}
#Prods li:hover ul, #Prods li.sfhover ul {
left: auto;
z-index:10;
}
You can see it working on this fiddle. Let me know if anymore info is needed and I will provide it.
One option is using the adjacent sibling selector (+) in your CSS, so some rules are only applied to the ul next to the a with id "workwear". For your specific case it would be:
#Prods li:hover a#Workwear + ul, #Prods li.sfhover a#Workwear + ul
Now that you have a rule for that particular dropdown, you can apply some CSS styling to it without affecting the rest.
For example, one thing that you could do is instead of displaying the dropdown at its position, translate it a bit to the left:
#Prods li:hover a#Workwear + ul, #Prods li.sfhover a#Workwear + ul {
transform: translate(-50%, 0%);
}
You can see the result here: http://jsfiddle.net/wmLfu1Lu/, and read more about the adjacent sibling selector here: http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors.

Add submenu to existing menu

Hi I have a basic menu for which I would like to add a submenu, that appears only when a certain menu link is hovered. Everything I have tried does not hide the submenu when a link is not hovered. Here is my code:
CSS
.navmenu{
float:right;
font-size: 13px;
font-weight:400;
text-transform: uppercase;
}
.navmenu li{
position: relative;
display: inline-block;
float: left;
}
.navmenu li a{
text-decoration:none;
color:#eee;
padding:15px 37px 19px 37px;
}
.navmenu li a:hover{
background:#36332e;
}
.active a{
background:#36332e;
}
HTML
<ul class="navmenu">
<li class="active">Home</li>
<li>About Us
<ul>
<li>Sub Link 1</li>
<li>SubLink 2</li>
</ul>
</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact Us</li>
</ul>
You need to initially hide the menu:
.navmenu li ul { display: none; }
and then display it when you hover over the nav item:
.navmenu li:hover ul { display: none; }
You should also be careful about defining styles that target .navmenu li or .navmenu li a because those will also target your submenu. You should instead use child selectors, giving you more control over the non-submenu links, so your selectors will look like:
.navmenu > li
.navmenu > li > a
I've encorperated some of those changes into this JSFiddle to get you started:
http://jsfiddle.net/Wexcode/B5P26/
Edit:
This is actually going to lose it's hover state when you hover over the submenu links:
.navmenu > li > a:hover {
background:#36332e;
}
Instead, you should do this:
.navmenu ul { position: absolute; }
.navmenu > li:hover { background: #e6332e; }
.navmenu > li > a { display: block; }
Since the <ul> is nested inside the <li> element, you won't lose the hover state when you hover over the submenu links. I updated the fiddle to reflect these changes.
<ul class="navmenu">
<li class="active">Home</li>
<li>About Us
<ul>
<li>
Sub Link 1
<ul>
</li> <a href=# >hi hi hi</a>
<ul>
<li>hello hello hello</li>
<li>hello hello hello</li>
<li>hello hello hello</li>
</ul>
</li>
</li><a href=# >hi hi hi</a> </li>
</li> <a href=# >hi hi hi</a> </li>
</ul>
</li>
<li>SubLink 2</li>
</ul>
</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact Us</li>
</ul>

Creating sub-menu for a child for a single drop down menu

I need a single drop down menu that is displayed only on hover. From the drop down menu list, I need a further list on hover on one of the child items.
The keyword/ parent is Subjects.
On hover (on the word Subjects) it has to display:
Maths
English
Spanish
History
Science
Extra
Marks
On hover on the child Extra, it has to display 3 further items:
Arts
Sports
Community
I have tried both dropdown and dropup menus, but the child menu items (ie Arts, Sports and Community) are displayed even as I hover on the parent Subjects. They have to appear only on hover on Extra.
I'm CSS challenged, tried my best from drop down scripts downloaded online. But none seem to address this situation.
Here's the HTML for the menu. Not sure if I'm doing it right.
<nav id="subjectsNav">
<ul>
<li class="last">SUBJECTS
<ul>
<li>Maths
</li>
<li>English
</li>
<li>Spanidsh
</li>
<li>History
</li>
<li>Science
</li>
<li>EXTRA
</li>
<ul id="extraNav">
<li>Arts
</li>
<li>Sports
</li>
<li>Community
</li>
</ul>
<li>Marks
</li>
</ul>
</li>
</ul>
</nav>
Need help with the HTML and CSS for the above. Yours answers are much appreciated. Many thanks for taking your time.
extraNav submenu must be inside of parent list item:
<ul id="subjectsNav">
<li>SUBJECTS
<ul>
<li>Maths
</li>
<li>English
</li>
<li>Spanidsh
</li>
<li>History
</li>
<li>Science
</li>
<li>EXTRA
<ul>
<li>Arts
</li>
<li>Sports
</li>
<li>Community
</li>
</ul>
</li>
<li>Marks
</li>
</ul>
</li>
</ul>
CSS:
/* Main */
#subjectsNav {
list-style: none;
}
#subjectsNav li {
width: 70px;
display: block;
float: left;
position: relative;
}
#subjectsNav li:hover > ul {
display: block;
}
/* Sub-menu */
#subjectsNav ul {
list-style: none;
left: 0;
margin: 0;
padding: 0;
display: none;
position: absolute;
z-index: 99999;
}
#subjectsNav ul li {
float: none;
display: block;
}
#subjectsNav ul ul {
top: 0;
left: 70px;
}
Demo:
http://jsfiddle.net/Bc2sv/