JSFiddle - React, Tailwind, and code Playground
HTML
<nav>
<li>One
<ul class = "grandpa">
<li>1.1</li>
<li>1.2
<ul class = "father">
<li>1.2.1</li>
<li>1.2.2
<ul class = "son">
<li>1.2.2.1</li>
<li>1.2.2.2
<ul class = "grandson">
<li>1.2.2.2.1</li>
<li>1.2.2.2.2</li>
<li>1.2.2.2.3</li>
</ul>
</li>
<li>1.2.2.3</li>
</ul>
</li>
<li>1.2.3</li>
</ul>
</li>
<li>1.3</li>
</ul>
</li>
<li>Two
<ul class = "grandpa">
<li>2.1</li>
<li>2.2
<ul class = "father">
<li>2.2.1</li>
<li>2.2.2
<ul class = "son">
<li>2.2.2.1</li>
<li>2.2.2.2</li>
<li>2.2.2.3</li>
</ul>
</li>
<li>1.2.3</li>
</ul>
</li>
<li>2.3</li>
</ul>
</li>
<li>Three
<ul class = "grandpa">
<li>3.1</li>
<li>3.2
<ul class = "father">
<li>3.2.1</li>
<li>3.2.2</li>
<li>3.2.3</li>
</ul>
</li>
<li>3.3</li>
</ul>
</li>
<li>Four
<ul class = "grandpa">
<li>4.1</li>
<li>4.2</li>
<li>4.3</li>
</ul>
</li>
<li>Five</li>
</nav>
CSS
*{
font-family: Georgia;
font-size: 1.05em;
transition: all .2s ease;
}
body{
margin: 0;
}
nav{
width: 40em;
height: 5em;
background: black;
position: absolute;
left: 50%;
margin: 1em 0 0 -20em;
text-align: center;
}
li{
list-style: none;
line-height: 4.5em;
color: white;
cursor: pointer;
}
nav li{
display: table-cell;
vertical-align: middle;
width: 7em;
height: 4.75em;
}
nav li:hover{
background: orange;
}
nav li:hover .grandpa{
display: block;
}
.grandpa li:hover .father{
display: block;
}
.father li:hover .son{
display: block;
}
.son li:hover .grandson{
display: block;
}
.grandpa, .father, .son, .grandson{
position: absolute;
display: none;
}
.grandpa li, .father li, .son li, .grandson li{
display: block;
}
.grandpa{
background: orange;
margin-top: .1em;
}
.grandpa li{
margin-left: -1.85em;
width: 6.38em;
}
.grandpa li:hover{
background: moccasin;
color: salmon;
}
.father{
background: moccasin;
margin: -4.3em 0 0 6.08em;
}
.father li{
margin-left: -1.7em;
width: 5.74em;
height: 4.32em;
line-height: 4.15em;
}
.father li:hover{
background: lavender;
color: burlywood;
}
.son{
background: lavender;
margin: -3.95em 0 0 5.45em;
}
.son li{
margin-left: -1.5em;
width: 5.2em;
height: 3.95em;
line-height: 3.65em;
}
.son li:hover{
background: lavenderblush;
color: darksalmon;
}
.grandson{
background: lavenderblush;
margin: -3.45em 0 0 4.95em;
}
.grandson li{
margin-left: -1.4em;
width: 4.8em;
height: 3.58em;
line-height: 3.3em;
}
.grandson li:hover{
background: lemonchiffon;
color: lightcoral;
}
JavaScript
/***
Author: Alexis LĂłpez (@AlexisThrasher)
*/