“How to create an expandable hamburger menu?”
DEMO: How It Looks
HTML
<header class="header"> <div class="header__menu menu"> <div class="menu__icon"> <span></span> </div> <nav class="menu__body"> <ul class="menu__list"> <li> <a data-goto="#home" href="" class="menu__link">Home</a></li> <li> <a data-goto="#section-1" href="" class="menu__link">Section 1</a></li> <li> <a data-goto="#section-2" href="" class="menu__link">Section 2</a></li> <li> <a data-goto="#section-3" href="" class="menu__link">Section 3</a></li> </ul> </nav> </div> </header>
CSS
body { background-color: black; font-family:sans-serif; } header a { color: #111 !important; text-decoration: none!important; font-weight: 200; font-size: 2.2rem; line-height: 1.2; display: block; } .header__menu { position: fixed; top: 34px; right: 30px; z-index: 10; } .menu__icon { z-index: 5; display: block; position: relative; width: 50px; height: 22px; cursor: pointer; } .menu__icon span, .menu__icon::before, .menu__icon::after { left: 0; position: absolute; height: 20%; width: 100%; transition: all 0.3s ease 0s; background-color: white; } .menu__icon::before, .menu__icon::after { content: ''; } .menu__icon::before { top: 0; } .menu__icon::after { bottom: 0; } .menu__icon span { top: 50%; transform: scale(1) translate(0, -50%); } .menu__icon._active span { transform: scale(0) translate(0, -50%); } .menu__icon._active::before { top: 50%; transform: rotate(-45deg) translate(0, -50%); } .menu__icon._active::after { bottom: 50%; transform: rotate(45deg) translate(0, 50%); } .menu__body { position: fixed; top: 0; right: -99%; width: 34%; height: 100%; background-color: rgba(255, 255, 255, 0.8); padding: 100px 30px 30px 30px; transition: right 0.3s ease 0s; overflow: auto; } .menu__body._active { right: 0; } .menu__list > li { flex-wrap: wrap; margin-bottom: 30px; } .menu__body ul { padding-left: 1rem; list-style: none; }
JavaScript
Link the below external Javascript into the bottom of your HTML.
<script type="text/javascript" src="https://blog.identitydesign.us/js/hamburger.js"></script>
With having the hamburger menu on your navigation, your website could look more sophisticated and clean.