I'm working on a personal project to increase my knowledge of HTML and CSS. I am working on creating a drop down menu for hyper links. I have the links styled, but the drop down lists don't appear when I hover over the selections.
-I am using links from a class I am taking in school because I have access to the server that they are hosted on and I don't have a server of my own.
This first section is the HTML for my lists.
<nav>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/index.html">Home Page</a> </li>
<li><a href="#">Lab 1 Links</a></li>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l1p4.html">Lab 1, Part 4</a></li>
</ul>
<li><a href="#">Lab 2 Links</a></li>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p1.html">Lab 2, Part 1</a></li>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p2.html">Lab 2, Part 2</a></li>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p3.html">Lab 2, Part 3</a></li>
</ul>
<li><a href="#">Lab 3 Links</a></li>
</ul>
</nav>
This second section is the css for styling and hover actions.
nav ul
{
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 6px;
border-radius: 5px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after
{
content: ""; clear: both; display: block;
}
nav ul li
{
float: left;
}
nav ul li:hover
{
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
nav ul li:hover a
{
color: #fff;
}
nav ul li a
{
display: block; padding: 10px 20px;
color: #757575; text-decoration: none;
}
nav ul ul
{
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
display: none;
}
nav ul ul li
{
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a
{
padding: 6px 20px;
color: #fff;
}
nav ul ul li a:hover
{
background: #4b545f;
}
nav ul li:hover > ul
{
display: block;
}
nav ul ul ul
{
position: absolute; left: 100%; top:0;
}
Can anyone help me pick out why the drop downs for Lab 1 Links and Lab 2 Links aren't appearing when I hover over them?
correct your html like this
<nav>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/index.html">Home Page</a>
</li>
<li><a href="#">Lab 1 Links</a>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l1p4.html">Lab 1, Part 4</a>
</li>
</ul>
</li>
<li><a href="#">Lab 2 Links</a>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p1.html">Lab 2, Part 1</a>
</li>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p2.html">Lab 2, Part 2</a>
</li>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p3.html">Lab 2, Part 3</a>
</li>
</ul>
</li>
<li><a href="#">Lab 3 Links</a>
</li>
</ul>
</nav>
Working fiddle example
http://jsfiddle.net/HB7Um/
Your HTML is invalid. You must put the submenu ul inside the parent li. You are closing the parent li too soon.
Try
<nav>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/index.html">Home Page</a> </li>
<li><a href="#">Lab 1 Links</a>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l1p4.html">Lab 1, Part 4</a></li>
</ul>
</li>
<li><a href="#">Lab 2 Links</a>
<ul>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p1.html">Lab 2, Part 1</a></li>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p2.html">Lab 2, Part 2</a></li>
<li><a href="http://webdev.spsu.edu/~cmilam/public/l2p3.html">Lab 2, Part 3</a></li>
</ul>
</li>
<li><a href="#">Lab 3 Links</a></li>
</nav>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.