Why my menu doesn't work? - html

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

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.

Expanding drop down menu on hover using css

I'm trying to get a drop down menu for my navbar so that when I hover over the tabs it opens a drop down menu with more options. Here is a fiddle of my code. The very final product should look like this, for now I just want to fix the drop down on hover part of it.
Here is a snippet of code im using in css to try and achieve this:
.dropdown {
display: none
}
.navbar-list li:hover .dropdown {
display: relative;
color: white;
text-decoration: none;
}
You are trying wrong approach, please change your css part
.navbar-list li:hover .dropdown {
display: block;
color: white;
text-decoration: none;
}
<ul class="navbar-list">
<li class="navbar-tags">OUR DNA
<ul class="dropdown">
<li>Risk</li>
</ul>
</li>
update code
Your HTML structure is wrong, and you need to use display: block on hover, not display: relative
But re: the HTML, a ul can't be a direct child of a ul. You need to nest the dropdowns in an li. That is not only correct markup, but it allows the hover to persist when you hover over an li that has nested menus. Otherwise, you would need to use li:hover + .dropdown to show the next .dropdown menu, but your :hover will stop once your mouse moves off of the li.
Also, each ul.dropdown that is in a single nested nav element could probably just be li's of a single ul, but what you have isn't incorrect, so I didn't change that.
.dropdown {
display: none
}
.navbar-tags:hover > .dropdown {
display: block;
color: white;
text-decoration: none;
}
.navbar-list a {
color: black;
text-decoration: none;
}
.navbar-tags {
margin: 20px;
}
.navbar-tags, .dropdown {
padding: 0;
list-style-type: none;
}
<ul class="navbar-list">
<li class="navbar-tags">
OUR DNA
<ul class="dropdown">
<li>Risk</li>
</ul>
</li>
<li class="navbar-tags">PROGRAMS
<ul class="dropdown">
<li>Adventure Sport</li>
</ul>
<ul class="dropdown">
<li>Entertainment</li>
</ul>
<ul class="dropdown">
<li>Collegiate</li>
</ul>
<ul class="dropdown">
<li>Individual</li>
</ul>
<ul class="dropdown">
<li>Commercial</li>
</ul>
</li>
<li class="navbar-tags">RESEARCH
<ul class="dropdown">
<li>Corporate Survey</li>
</ul>
<ul class="dropdown">
<li>Individual Survey</li>
</ul>
</li>
<li class="navbar-tags">STORIES</li>
</ul>
1 ) Your HTML structure is wrong.
2) use display: block instead of display: relative.
Change your Code Like THis :
.dropdown {
display: none
}
.navbar-list li:hover > .dropdown {
display: block;
color: white;
text-decoration: none;
}
.navbar-list a {
color: black;
text-decoration: none;
}
.navbar-tags {
padding: 0;
list-style-type: none;
margin: 20px;
}
<ul class="navbar-list">
<li class="navbar-tags">OUR DNA
<ul class="dropdown">
<li>Risk</li>
</ul>
</li>
<li class="navbar-tags">PROGRAMS
<ul class="dropdown">
<li>Professional</li>
</ul>
<ul class="dropdown">
<li>Adventure Sport</li>
</ul>
<ul class="dropdown">
<li>Entertainment</li>
</ul>
<ul class="dropdown">
<li>Collegiate</li>
</ul>
<ul class="dropdown">
<li>Individual</li>
</ul>
<ul class="dropdown">
<li>Commercial</li>
</ul>
</li>
<li class="navbar-tags">RESEARCH
<ul class="dropdown">
<li>Corporate Survey</li>
</ul>
<ul class="dropdown">
<li>Individual Survey</li>
</ul>
</li>
<li class="navbar-tags">STORIES</li>
</ul>

Adding 2nd level Dropdown Navbar to 1 level

<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

Create a nested ordered list in a tabular style with css

Hi I am looking to display my ordered list this:
so the first node and the first nested node appear on the top line and the remaining nested nodes appear under the 2nd column (under red).
Apples Red
Green
Yellow
Banana Yellow
html:
<ul class="lst" id="list_Apple">
<li>Apple</li>
<ul>
<li id="Apple">Red</li>
<li id="Apple">Green</li>
<li id="Apple">Yellow</li>
</ul>
</ul>
<ul class="lst" id="list_Banana">
<li>Banana</li>
<ul>
<li id="Banana">Yellow</li>
</ul>
</ul>
There is a slight mistake in your html. The <ul> tag should be inside a <li>.
HTML:
<ul class="lst" id="list_Apple">
<li>Apple</li>
<li>
<ul>
<li id="Apple">Red</li>
<li id="Apple">Green</li>
<li id="Apple">Yellow</li>
</ul>
</li>
</ul>
<ul class="lst" id="list_Banana">
<li>Banana</li>
<li>
<ul>
<li id="Banana">Yellow</li>
</ul>
</li>
</ul>
And add this CSS:
.lst {
clear: both;
}
.lst li {
list-style: none;
}
.lst > li {
float: left;
}
Here's a Fiddle: http://jsfiddle.net/rayg8ua9/1/
lithanks... Yes I missed the li tag.
.lst {
clear: both;
padding-top: 10px;
}
.lst li {
list-style: none;
width:100px;
}
.lst > li {
float: left;
}

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/