I've built a nested menu using the ul/li tags, and I'm looking to align the second and third sub-menus horizontally with the first submenu.
Here is my current visual layout: https://i.sstatic.net/4TctL.png, and this is what I want it to look like: https://i.sstatic.net/ehP2G.png
CSS/HTML:
body {
background-color: #000;
font-size: 1.6vw;
color: #FFF;
}
div#header {
width: 65vw;
margin-left: auto;
margin-right: auto;
}
#nav {
font-size: 1.4em;
white-space: nowrap;
position: absolute;
}
#nav ul {
display: inline-table;
list-style-type: none;
margin: 0px;
border-style: none;
padding: 0px;
}
#nav ul li {
display: table-cell;
}
#nav ul li a {
margin: 0px 0px 0px 20px;
padding: 0px 0px 0px 5px;
border-left-style: solid;
border-left-width: 7px;
border-color: #FFF;
color: #FFF;
text-decoration: none;
}
#nav ul li .active {
color: #F00;
border-left-color: #F00;
}
#nav ul li a:hover {
color: #F00;
border-color: #F00;
}
#nav ul li ul {
position: absolute;
display: none;
}
#nav ul li:hover ul {
display: block;
margin: 0px;
padding: 5px 0px 0px;
}
#nav ul li:hover ul li ul {
display: none;
}
#nav ul li:hover ul li:hover ul {
display: block;
margin: 0px;
padding: 5px 0px 0px;
font-size: 0.85em
}
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="header">
<div id="nav">
<ul>
<li><a href="#" class="active">Menu 1</a>
</li>
<li><a href="#">Menu 2</a>
<ul>
<li><a href="#">Submenu 1</a>
<ul>
<li><a href="#">Subsubmenu 1</a>
</li>
<li><a href="#">Subsubmenu 2</a>
</li>
</ul>
</li>
<li><a href="#">Submenu 2</a>
<ul id="sub2">
<li><a href="#">Subsubmenu 3</a>
</li>
<li><a href="#">Subsubmenu 4</a>
</li>
<li><a href="#">Subsubmenu 5</a>
</li>
<li><a href="#">Subsubmenu 6</a>
</li>
<li><a href="#">Subsubmenu 7</a>
</li>
</ul>
</li>
<li><a href="#">Submenu 3</a>
<ul id="sub3">
<li><a href="#">Subsubmenu 8</a>
</li>
<li><a href="#">Subsubmenu 9</a>
</li>
<li><a href="#">Subsubmenu 10</a>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Menu 3</a>
</li>
<li><a href="#">Menu 4</a>
</li>
<li><a href="#">Menu 5</a>
</li>
<li><a href="#">Menu 6</a>
</li>
</ul>
</div>
</div>
</body>
</html>
The only solution I've thought of so far is manually adjusting the margin to the left by adding the following:
#nav ul li:hover ul li:hover ul#sub2 {
margin-left: -10.8vw
}
#nav ul li:hover ul li:hover ul#sub3 {
margin-left: -21.5vw
}
I initially used "vw" as a unit because I have a 16:9 monitor (1366x768 resolution) assuming it would scale on other 16:9 monitors, but testing on different resolutions shows that the sub-menus are not aligned correctly. Do you think minor adjustments can fix this issue, or do I need to consider rewriting the code with fixed pixel sizes?