I have four list items in my <nav> bar: Home, Projects, Resume, Contact
Projects item has further five list items.
When I hover on "Projects", these items appear as a drop down block, but they are not aligned with the parent element.
/*Display Nav elements in row*/
nav > ul > li
{
display: inline-block;
background-color: #D2D4C9;
}
/*Hide child elements and fix position*/
nav > ul > li > div
{
display: none;
position: absolute;
visibility: hidden;
z-index: 100;
}
/*Expand list on hover*/
nav > ul > li:hover > div
{
display: block;
visibility: visible;
}
/*Display child elements as block*/
nav > ul > li > div ul > li
{
display: block;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<link rel="stylesheet" href="index.css">
<title> My portfolio </title>
</head>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Projects</a>
<div>
<ul>
<li><a href="#">Proj1</a></li>
<li><a href="#">Proj2</a></li>
<li><a href="#">Proj3</a></li>
<li><a href="#">Proj4</a></li>
<li><a href="#">Proj5</a></li>
</ul>
</div>
</li>
<li><a href="#">Resume</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</html>
Here's the output I'm getting.