I'm struggling to design a navigation layout for my website where I want to display the main menu items like this:
- Menu 1
- Menu 2
- Menu 3
- Menu 4
- Menu 5
and have their respective sub-menus displayed horizontally on their main menu pages like this:
SubMenu 1.1 | SubMenu 1.2 | SubMenu 1.3 | SubMenu 1.4 | SubMenu 1.5 | ...
I should mention that my site is a single-page application that dynamically loads content into a div using jQuery Ajax. The loaded pages contain only the required content without any additional HTML elements like <html>
, <head>
, or <body>
. So, what I want is when I click on "Menu 1" and the corresponding page loads, the sub-menus from "SubMenu 1.1" to "SubMenu 1.12" should be displayed horizontally on that page at the same time, while keeping "Menu 1" active. Please refer to the image below.
Here is the code I currently have, which results in a dropdown instead of the desired horizontal layout - you can see it in this JSFiddle.
<nav>
<ul>
<li><a href="#Menu 1">Menu 1</a>
<ul>
<li><a href="#SubMenu 1.1">SubMenu 1.1</a></li>
<li><a href="#SubMenu 1.2">SubMenu 1.2</a></li>
<li><a href="#SubMenu 1.3">SubMenu 1.3</a></li>
<li><a href="#SubMenu 1.4">SubMenu 1.4</a></li>
<li><a href="#SubMenu 1.5">SubMenu 1.5</a></li>
<li><a href="#SubMenu 1.6">SubMenu 1.6</a></li>
<li><a href="#SubMenu 1.7">SubMenu 1.7</a></li>
<li><a href="#SubMenu 1.8">SubMenu 1.8</a></li>
<li><a href="#SubMenu 1.9">SubMenu 1.9</a></li>
<li><a href="#SubMenu 1.10">SubMenu 1.10</a></li>
<li><a href="#SubMenu 1.11">SubMenu 1.11</a></li>
<li><a href="#SubMenu 1.12">SubMenu 1.12</a></li>
</ul>
</li>
<li><a href="#Menu 2">Menu 2</a>
<ul>
<li><a href="#SubMenu 2.1">SubMenu 2.1</a></li>
<li><a href="#SubMenu 2.2">SubMenu 2.2</a></li>
<li><a href="#SubMenu 2.3">SubMenu 2.3</a></li>
<li><a href="#SubMenu 2.4">SubMenu 2.4</a></li>
<li><a href="#SubMenu 2.5">SubMenu 2.5</a></li>
<li><a href="#SubMenu 2.6">SubMenu 2.6</a></li>
<li><a href="#SubMenu 2.7">SubMenu 2.7</a></li>
<li><a href="#SubMenu 2.8">SubMenu 2.8</a></li>
<li><a href="#SubMenu 2.9">SubMenu 2.9</a></li>
<li><a href="#SubMenu 2.10">SubMenu 2.10</a></li>
<li><a href="#SubMenu 2.11">SubMenu 2.11</a></li>
<li><a href="#SubMenu 2.12">SubMenu 2.12</a></li>
</ul>
</li>
<li><a href="#Menu 3">Menu 3</a>
<ul>
<li><a href="#SubMenu 3.1">SubMenu 3.1</a></li>
<li><a href="#SubMenu 3.2">SubMenu 3.2</a></li>
<li><a href="#SubMenu 3.3">SubMenu 3.3</a></li>
<li><a href="#SubMenu 3.4">SubMenu 3.4</a></li>
<li><a href="#SubMenu 3.5">SubMenu .5</a></li>
<li><a href="#SubMenu 3.6">SubMenu 35.6</a></li>
<li><a href="#SubMenu 3.7">SubMenu 3.7</a></li>
<li><a href="#SubMenu 3.8">SubMenu 3.8</a></li>
<li><a href="#SubMenu 3.9">SubMenu 3.9</a></li>
<li><a href="#SubMenu 3.10">SubMenu 3.10</a></li>
<li><a href="#SubMenu 3.11">SubMenu 3.11</a></li>
<li><a href="#SubMenu 3.12">SubMenu 3.12</a></li>
</ul>
</li>
<li><a href="#Menu 4">Menu 4</a>
<ul>
<li><a href="#SubMenu 4.1">SubMenu 4.1</a></li>
<li><a href="#SubMenu 4.2">SubMenu 4.2</a></li>
<li><a href="#SubMenu 4.3">SubMenu 4.3</a></li>
<li><a href="#SubMenu 4.4">SubMenu 4.4</a></li>
<li><a href="#SubMenu 4.5">SubMenu 4.5</a></li>
<li><a href="#SubMenu 4.6">SubMenu 4.6</a></li>
<li><a href="#SubMenu 4.7">SubMenu 4.7</a></li>
<li><a href="#SubMenu 4.8">SubMenu 4.8</a></li>
<li><a href="#SubMenu 4.9">SubMenu 4.9</a></li>
<li><a href="#SubMenu 4.10">SubMenu 4.10</a></li>
<li><a href="#SubMenu 4.11">SubMenu 4.11</a></li>
<li><a href="#SubMenu 4.12">SubMenu 4.12</a></li>
</ul>
</li>
<li><a href="#Menu 5">Menu 5</a>
<ul>
<li><a href="#SubMenu 5.1">SubMenu 5.1</a></li>
<li><a href="#SubMenu 5.2">SubMenu 5.2</a></li>
<li><a href="#SubMenu 5.3">SubMenu 5.3</a></li>
<li><a href="#SubMenu 5.4">SubMenu 5.4</a></li>
<li><a href="#SubMenu 5.5">SubMenu 5.5</a></li>
<li><a href="#SubMenu 5.6">SubMenu 5.6</a></li>
<li><a href="#SubMenu 5.7">SubMenu 5.7</a></li>
<li><a href="#SubMenu 5.8">SubMenu 5.8</a></li>
<li><a href="#SubMenu 5.9">SubMenu 5.9</a></li>
<li><a href="#SubMenu 5.10">SubMenu 5.10</a></li>
<li><a href="#SubMenu 5.11">SubMenu 5.11</a></li>
<li><a href="#SubMenu 5.12">SubMenu 5.12</a></li>
</ul>
</li>
</ul>
</nav>
And here is the associated CSS:
nav li {
display:inline-block;
padding:0 0.4em;
height:1.4em; line-height:1.4em;
position:relative;
}
nav li.sub:after { content:'\25ba'; float:right; vertical-align:middle; font-size:50% }
nav > ul > li { cursor:default }
nav li ul { display:none }
nav li li { display:block; width:8em }
nav li:hover > ul { display:block; position:absolute; top:1.4em; left:-1px; width:8em; z-index:10 }
nav li li:hover ul{ left:8em; top:-1px }
nav li { color:black; background:#C2C2C2; border:1px solid #121314; }
nav li li { color:black; background:#C2C2C2; border-color:#696 }
nav li li li { color:black; background:#C2C2C2; border-color:#669 }
nav li:hover { background:#828282; color:#fee }
nav li li:hover { background:#828282; color:#efe }
nav li li li:hover { background:#828282; color:#eef }
nav li li { border-top-width:0 }
nav li li:first-child { border-top-width:1px }
For a better understanding, please refer to this image: https://i.sstatic.net/k7j6E.jpg
Any assistance with achieving this navigation layout would be highly appreciated. Thank you!