I am learning CSS and trying to get a nested navigation menu working. I am able to float the main items and stack all the child elements under it, but the position relative for the child menus are not working. I intend to move the child menu items to the right relative to its parent. Please let me know where I am going wrong.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<style>
*{
margin:0;
padding:0;
}
h1{
text-align: center;
text-decoration: underline;
margin-bottom: 10px;
}
li{
list-style: none;
}
ul li a{
text-decoration: none;
display: block;
width:100px;
height: 25px;
border: 1px solid green;
text-align: center;
}
.main > li{
float:left;
position: relative;
}
.main > li > li {
position: absolute;
top:0px;
left:10px;
}
</style>
</head>
<body>
<h1>Hello Plunker!</h1>
<ul class="main">
<li><a href="#">Menu 1</a>
<ul class="sub1">
<li><a href="#">Menu 1.1</a>
<ul class="sub2">
<li><a href="#">Menu 1.1.1</a></li>
<li><a href="#">Menu 1.1.2</a></li>
<li><a href="#">Menu 1.1.3</a></li>
<li><a href="#">Menu 1.1.4</a></li>
</ul>
</li>
<li><a href="#">Menu 1.2</a></li>
<li><a href="#">Menu 1.3</a></li>
<li><a href="#">Menu 1.4</a></li>
</ul>
</li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
<li><a href="#">Menu 4</a></li>
</ul>
</body>
</html>
Link to Plnkr - Plnkr Link