Jump to content

[HTML & CSS] Dropdown Menu's

Peeeeeeeeeeynk

I have been practicing on how to make dropdown menu's the problem is I can't get my hover to work every time I want my sub menus to appear.

Please help. D:

Below is some code that I made on my drop down menu.

 

HTML

<body>  

<nav>

   <ul>
         <li><a href="#">List Item #1</a></li>
              <ul>
                    <li><a href="#">Sub Menu #1</a></li>
                    <li><a href="#">Sub Menu #2</a></li>
                    <li><a href="#">Sub Menu #3</a></li>
             </ul>
         <li><a href="#">List Item #2</a></li>
         <li><a href="#">List Item #3</a></li>
 </ul>
</nav>
</body>
 
CSS
nav
{
background: black;
}
 
nav ul li a
{
color:white;
font-family:arial;
text-decoration: none;
display: block;
padding:10px;
text-align: center;
}
 
nav ul li 
{
display:inline-block;
}
nav ul li a:hover 
{
background-color: gray;
}
ul
{
margin-left:30px;
position: relative;
}
nav ul ul
{
 
display:none;
}
 
nav ul li:hover > ul
{
display: block;
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

the HTML part seems to be correct to me at least. Try unlinking the CSS to the HTML (which I assume you've linked already) and open the HTML. If it works like that then you've got a CSS error.

 

 

EDIT: I assume you could always just use an example code from something like w3schools.com too.

NCASE M1 i5-9600k  GTX 1080 FE Z370N-WIFI SF600 NH-U9S LPX 32GB 960EVO

I'm a self-identifying Corsair Nvidia Fanboy; Get over it.

Link to comment
Share on other sites

Link to post
Share on other sites

First of all, I apologise for spelling/grammar or a downright wrong answer. I may have had one or two or two dozen to drink.

Anyways, li:hover > ul is applying the style to all children of the li tag and the ul doesn't look like it's actually nested inside the li tag, so the ul isn't a child of the li

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×