JSFiddle - React, Tailwind, and code Playground
by Kocsten
HTML
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<nav class="animated flipInX">
<ul>
<li> <a href="#">
<div class="fa fa-home"></div>
</a> </li>
<li> <a href="#"> About </a> </li>
<li class="sub-menu"> <a href="#"> Products <i class="fa fa-angle-down"></i> </a>
<ul>
<li> <a href="#"> Product Item </a> </li>
<li> <a href="#"> Product Item </a> </li>
<li> <a href="#"> Product Item </a> </li>
</ul>
</li>
<li class="sub-menu"> <a href="#"> Services <i class="fa fa-angle-down"></i> </a>
<ul>
<li> <a href="#"> Product Item </a> </li>
<li> <a href="#"> Product Item </a> </li>
<li> <a href="#"> Product Item </a> </li>
</ul>
</li>
<li> <a href="#"> Contact Us </a> </li>
</ul>
</nav>
CSS
nav ul {
background: #2ecc71;
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
position: relative;
display: inline-block;
margin-right: -4px;
text-align: center;
}
nav ul li:first-child a {
background: #27ae60;
width: 49px;
padding: 15px 0;
}
nav ul li:last-child { margin: 0; }
nav ul li a {
display: block;
background: #2ecc71;
padding: 15px 20px;
color: #fff;
font-size: 14px;
text-decoration: none;
transition: 0.2s linear;
}
nav ul li a:hover { background: #27ae60; }
nav ul li ul {
position: absolute;
top: 100%;
left: 0;
width: 240px;
border-bottom: 4px solid #2ecc71;
}
nav ul li ul li {
display: block;
width: 100%;
margin: 0;
text-align: left;
}
nav ul li ul li a {
display: block;
background: #2c3e50;
padding: 10px 15px;
}
nav ul li ul li a:first-child {
background: #2c3e50;
width: auto;
border-left: 4px solid transparent;
padding: 10px 15px;
font-size: 14px;
}
nav ul li ul li a:hover {
background: #34495e;
border-left: 4px solid #2ecc71;
}
JavaScript
$('.sub-menu ul').hide();
$(".sub-menu a").click(function () {
$(this).parent(".sub-menu").children("ul").slideToggle("200");
$(this).find("i.fa").toggleClass("fa-angle-up fa-angle-down");
});