Demo
  • 3.00 KB
  • HTML, CSS, JS
  • Menu
  • vertical
  • MIT License
HTML
<link href="https://fonts.googleapis.com/css?family=Quicksand:400,700" rel="stylesheet" type="text/css" />
<link href="https://netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.min.css" rel="stylesheet" />
<ul class="form">
    <li>
        <a class="profile" href="#"><i class="icon-user"></i>Edit Profile</a>
    </li>
    <li class="selected">
        <a class="messages" href="#"><i class="icon-envelope-alt"></i>Messages <em>5</em></a>
    </li>
    <li>
        <a class="settings" href="#"><i class="icon-cog"></i>App Settings</a>
    </li>
    <li>
        <a class="logout" href="#"><i class="icon-signout"></i>Logout</a>
    </li>
</ul>
CSS
ul.form {
    font-family: Quicksand;
    font-weight: 700;
    position: relative;
    background: #fff;
    width: 250px;
    margin: auto;
    padding: 0;
    list-style: none;
    overflow: hidden;

    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;

    -webkit-box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.1);
    box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.1);
}

.form li a {
    width: 225px;
    padding-left: 20px;
    height: 50px;
    line-height: 50px;
    display: block;
    overflow: hidden;
    position: relative;
    text-decoration: none;
    text-transform: uppercase;
    font-size: 14px;
    color: #686868;

    -webkit-transition: all 0.2s linear;
    -moz-transition: all 0.2s linear;
    -o-transition: all 0.2s linear;
    transition: all 0.2s linear;
}

.form li a:hover {
    background: #efefef;
}

.form li a.profile {
    border-left: 5px solid #008747;
}

.form li a.messages {
    border-left: 5px solid #fecf54;
}

.form li a.settings {
    border-left: 5px solid #cf2130;
}

.form li a.logout {
    border-left: 5px solid #dde2d5;
}

.form li:first-child a:hover,
.form li:first-child a {
    -webkit-border-radius: 5px 5px 0 0;
    -moz-border-radius: 5px 5px 0 0;
    border-radius: 5px 5px 0 0;
}

.form li:last-child a:hover,
.form li:last-child a {
    -webkit-border-radius: 0 0 5px 5px;
    -moz-border-radius: 0 0 5px 5px;
    border-radius: 0 0 5px 5px;
}

.form li a:hover i {
    color: #ea4f35;
}

.form i {
    margin-right: 15px;

    -webkit-transition: all 0.2s linear;
    -moz-transition: all 0.2s linear;
    -o-transition: all 0.2s linear;
    transition: all 0.2s linear;
}

.form em {
    font-size: 10px;
    background: #ea4f35;
    padding: 3px 5px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    font-style: normal;
    color: #fff;
    margin-top: 17px;
    margin-right: 15px;
    line-height: 10px;
    height: 10px;
    float: right;
}

.form li.selected a {
    background: #efefef;
}
JS
$("ul.form li a").click(function (e) {
    e.preventDefault();
    e.stopPropagation;
    $(this).closest("ul").find(".selected").removeClass("selected");
    $(this).parent().addClass("selected");
});

The code snippet we’re looking at is a beautiful blend of HTML, CSS, and JavaScript, designed to create a sleek vertical menu that’s both functional and eye-catching. Starting with HTML, the heart of our menu, it lays out a simple yet elegant structure using an unordered list <ul>, where each list item <li> represents a different menu option. Each option is styled as a clickable link <a>, enhanced with icons for a more intuitive user experience.

Moving on to the CSS, this is where the magic really happens, bringing our vertical menu to life with style. The CSS targets our menu with a class selector .form, applying a clean, modern look with a touch of sophistication. It sets a specific width, background color, and border-radius for smooth, rounded edges, creating a visually appealing container for our menu items. Each link within the menu is given ample padding, a specific height, and a unique color-coded border to the left, distinguishing each action visually. Hover effects are also added for a subtle, interactive feel, changing the background color of the menu items as the mouse passes over them.

Lastly, the JavaScript part adds interactive functionality to our vertical menu. Using jQuery, a popular JavaScript library, it listens for click events on the menu links. When a link is clicked, the script dynamically removes the selected class from the currently active menu item and adds it to the clicked item. This not only highlights the active section for the user but also prevents the default action of the link, ensuring the page doesn’t navigate away when the menu items are clicked.

In essence, this code snippet elegantly combines HTML, CSS, and JavaScript to create a vertical Menu that’s not just visually appealing but also interactive, enhancing the user experience with smooth transitions and clear, actionable items.

  •  Menu #174
    Menu #23
    Menu #23
    • HTML, CSS, JS
    • 9.83 KB
    • Vertical
    View Details
  •  Menu #175
    Menu #22
    Menu #22
    • HTML, CSS
    • 5.96 KB
    • Dropdown, Vertical
    View Details
  •  Menu #175
    Menu #21
    Menu #21
    • HTML, CSS
    • 1.62 KB
    • Sidebar, Sliding, Vertical
    View Details
  •  Menu #174
    Menu #20
    Menu #20
    • HTML, CSS
    • 4.94 KB
    • Sliding, Vertical
    View Details
  •  Menu #174
    Menu #19
    Menu #19
    • HTML, CSS
    • 8.15 KB
    • Hamburger, Sliding, Vertical
    View Details
  •  Menu #174.5
    Menu #18
    Menu #18
    • HTML, CSS
    • 2.87 KB
    • Vertical
    View Details
Menu