Demo
  • 8.15 KB
  • HTML, CSS
  • Menu
  • hamburger, sliding, vertical
  • MIT License
HTML
<nav class="vert-menu" role="navigation">
    <div class="top-header">
        <div class="navBurger">
            <div class="burger"></div>
        </div>
    </div>

    <ul id="menu-vertical-menu" class="nav">
        <li><a href="#">This menu</a></li>
        <li><a href="#">is built from</a></li>
        <li><a href="#">WP navigation</a></li>
        <li><a href="#">and only made</a></li>
        <li><a href="#">with custom</a></li>
        <li><a href="#">css !</a></li>
    </ul>
</nav>
CSS
nav.vert-menu a {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
nav.vert-menu {
    width: 60px;
    height: 100%;
    left: 0;
    -webkit-transition: left 0.5s ease-in-out 0.2s;
    -o-transition: left 0.5s ease-in-out 0.2s;
    -moz-transition: left 0.5s ease-in-out 0.2s;
    transition: left 0.5s ease-in-out 0.2s;
    position: fixed;
    display: inline-block;
    background-color: #3a4151;
    z-index: 1000;
}
nav.vert-menu {
    height: 100%;
    width: 60px;
    -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
nav.vert-menu .top-header {
    background-color: #3a4151;
    position: relative;
}
nav.vert-menu:before {
    content: " ";
    height: 100%;
    width: 0px;
    background-color: #424a5c;
    position: absolute;
    left: 60px;
    -webkit-transition: width 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    -o-transition: width 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    -moz-transition: width 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    transition: width 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
nav.vert-menu .navBurger {
    cursor: pointer;
    width: 100%;
    height: 45px;
}
nav.vert-menu .navBurger .burger {
    margin-left: 18px;
    margin-top: 30px;
    cursor: pointer;
}
nav.vert-menu .navBurger .burger,
nav.vert-menu .navBurger .burger::before,
nav.vert-menu .navBurger .burger::after {
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    position: absolute;
    z-index: 100;
    width: 24px;
    height: 4px;
    background: white;
    -webkit-transition: all 0.3s;
    -o-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
}
nav.vert-menu .navBurger .burger::before,
nav.vert-menu .navBurger .burger::after {
    content: "";
    display: block;
}
nav.vert-menu .navBurger .burger::before {
    margin-top: -8px;
}
nav.vert-menu .navBurger .burger::after {
    margin-top: 8px;
}
nav.vert-menu ul {
    position: absolute;
    padding: 0;
    width: 100%;
    margin-top: 20px;
}
nav.vert-menu ul li {
    font-size: 14px;
    width: 60px;
    height: 40px;
    cursor: pointer;
    position: relative;
    display: block;
}
nav.vert-menu ul li a {
    width: 150px;
    color: white;
    position: relative;
    z-index: 0;
    opacity: 0;
    left: -80px;
    text-transform: uppercase;
    -webkit-transition: left 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045), opacity 0.15s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    -o-transition: left 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045), opacity 0.15s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    -moz-transition: left 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045), opacity 0.15s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    transition: left 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045), opacity 0.15s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    color: #fff;
    text-decoration: none;
    display: block;
    padding: 15px;
}
nav.vert-menu ul li:before {
    z-index: 10;
    content: " ";
    width: 8px;
    height: 8px;
    background-color: transparent;
    position: absolute;
    left: 26px;
    top: 16px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    border: 2px solid white;
    -webkit-transform: scale(1) translate3d(0, 0, 0);
    -moz-transform: scale(1) translate3d(0, 0, 0);
    transform: scale(1) translate3d(0, 0, 0);
    -webkit-transition: all 0.2s ease-in-out;
    -o-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease-in-out;
    transition: all 0.2s ease-in-out;
}
nav.vert-menu ul li a:hover,
nav.vert-menu ul li a:active,
nav.vert-menu ul li a:visited,
nav.vert-menu ul li a:focus {
    background-color: transparent !important;
    color: white;
}
nav.vert-menu ul li:hover:before {
    background-color: white;
}
nav.vert-menu ul li.active:before,
nav.vert-menu ul li:hover:before {
    -webkit-transform: scale(1.5) translate3d(0, 0, 0);
    -moz-transform: scale(1.5) translate3d(0, 0, 0);
    transform: scale(1.5) translate3d(0, 0, 0);
    background-color: white;
}
nav.vert-menu:hover:before {
    width: 160px;
    -webkit-transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    -o-transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    -moz-transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
nav.vert-menu:hover .burger {
    -webkit-transform: rotate(45deg) translate3d(0, 0, 0);
    -moz-transform: rotate(45deg) translate3d(0, 0, 0);
    transform: rotate(45deg) translate3d(0, 0, 0);
}
nav.vert-menu:hover .burger::before {
    margin-top: 0px;
    -webkit-transform: rotate(-90deg) translate3d(0, 0, 0);
    -moz-transform: rotate(-90deg) translate3d(0, 0, 0);
    transform: rotate(-90deg) translate3d(0, 0, 0);
}
nav.vert-menu:hover .burger::after {
    margin-top: 0px;
    -webkit-transform: rotate(0deg) translate3d(0, 0, 0);
    -moz-transform: rotate(0deg) translate3d(0, 0, 0);
    transform: rotate(0deg) translate3d(0, 0, 0);
}
nav.vert-menu:hover li a {
    left: 70px;
    opacity: 1;
    -webkit-transition-duration: 0.4s;
    -moz-transition-duration: 0.4s;
    -o-transition-duration: 0.4s;
    transition-duration: 0.4s;
    -webkit-transition-property: left, opacity;
    -o-transition-property: left, opacity;
    -moz-transition-property: left, opacity;
    transition-property: left, opacity;
    -webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    -moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    -o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
nav.vert-menu:hover li:nth-child(1) a {
    -webkit-transition-delay: 0.3s;
    -moz-transition-delay: 0.3s;
    -o-transition-delay: 0.3s;
    transition-delay: 0.3s;
}
nav.vert-menu:hover li:nth-child(2) a {
    -webkit-transition-delay: 0.34s;
    -moz-transition-delay: 0.34s;
    -o-transition-delay: 0.34s;
    transition-delay: 0.34s;
}
nav.vert-menu:hover li:nth-child(3) a {
    -webkit-transition-delay: 0.38s;
    -moz-transition-delay: 0.38s;
    -o-transition-delay: 0.38s;
    transition-delay: 0.38s;
}
nav.vert-menu:hover li:nth-child(4) a {
    -webkit-transition-delay: 0.42s;
    -moz-transition-delay: 0.42s;
    -o-transition-delay: 0.42s;
    transition-delay: 0.42s;
}
nav.vert-menu:hover li:nth-child(5) a {
    -webkit-transition-delay: 0.46s;
    -moz-transition-delay: 0.46s;
    -o-transition-delay: 0.46s;
    transition-delay: 0.46s;
}
nav.vert-menu:hover li:nth-child(6) a {
    -webkit-transition-delay: 0.5s;
    -moz-transition-delay: 0.5s;
    -o-transition-delay: 0.5s;
    transition-delay: 0.5s;
}
nav.vert-menu:hover li:nth-child(7) a {
    -webkit-transition-delay: 0.54s;
    -moz-transition-delay: 0.54s;
    -o-transition-delay: 0.54s;
    transition-delay: 0.54s;
}
nav.vert-menu:hover li:nth-child(8) a {
    -webkit-transition-delay: 0.58s;
    -moz-transition-delay: 0.58s;
    -o-transition-delay: 0.58s;
    transition-delay: 0.58s;
}

The code snippet we’re diving into today paints the picture of a sleek, interactive web element: a vertical menu with a hamburger menu icon that reveals a sliding menu upon interaction. Imagine a compact, discreet column on the side of your webpage that, with a simple hover or click, blossoms open to present a list of options. This is the magic of combining HTML and CSS to create a user-friendly and visually appealing navigation tool.

At the heart of this design is the vertical menu, styled and structured using HTML. The <nav> tag wraps the entire menu, indicating its role in navigation, with a list of links <a> nested within <li> tags inside an <ul>. This semantic HTML structure not only aids in accessibility but also provides a clean, organized scaffold for styling. The inclusion of a div with a class of navBurger holds the hamburger icon, consisting of a series of styled divs that visually represent the iconic three lines of the hamburger menu.

CSS breathes life into this structure, transforming it into a sliding menu that engages users. Through a series of transitions and transforms, the hamburger icon animates into a close icon when the menu is active, signaling to users that they can retract the menu. The vertical menu itself is positioned off-screen initially, sliding into view when the user interacts with the hamburger icon. The styling ensures that the menu is not just functional but also a seamless part of the website’s aesthetic, with smooth transitions that enhance the user experience.

This integration of HTML and CSS showcases how a few lines of code can significantly enhance the interactivity and visual appeal of web navigation. The hamburger menu serves as a space-saving solution, while the sliding mechanism makes the navigation experience more engaging. The vertical orientation of the menu offers a modern twist to traditional horizontal navigation bars, fitting perfectly into the contemporary web design landscape where user experience and interface design hold paramount importance.

Menu