Advertisement
CSS

HTML 5 Vertical Navigation Menu

Post image

There are two different types of navigation menus in HTML, vertical, and horizontal. This tutorial will take you through creating a stylish CSS 3 vertical menu. I'll show you how to create a basic menu, all the way through to an animated sliding menu - no Javascript needed.

Vertical menus are very similar to horizontal menus, the main difference being the type of display setting being used. Let's begin.

Basic HTML 5 Menu

Here's what we'll be creating for our basic menu -

See the Pen Vertical HTML menu by lawnch (@lawnch) on CodePen.

Default CSS

We need to start by defining some basic CSS styles such as the body, and box-sizing styles. Importantly here we're defining box-sizing: border-box;. This treats padding and borders differently to the traditional method that would add any values to the standard width. That means if you define a width as 25%, it stays at 25%. Normally that would be 25% + padding + border.

* {
	margin: 0;
	padding: 0;
	outline: none;
	
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

body {
    background: #eee;
    color: #444;
    -webkit-font-smoothing: antialiased;
    font-family: 'Helvetica Neue', sans-serif;
    font-size: 20px;
    font-weight: 400;
    height: auto !important;
    height: 100%;
    min-height: 100%;
    text-rendering: optimizeLegibility;
}

div.wrapper {
  margin: 20px auto;
  width: 350px;
}

Most of the styles defined above will be standard and don't specifically matter for our example. You don't HAVE to include these when creating the menu for your own website.

Text-rendering allows the browser to choose quality of text over speed of render, making your text look nicer.

The wrapper CSS is also not needed, it simply specifies the width of the menu and makes it sit in the center of the page. By placing the menu in a container element such as a side-bar, you'll overwrite the need for the wrapper.

Basic Vertical Menu

The first thing to create is our basic list and container element. As we're using HTML 5 we can use the <nav> element.

Our HTML should look like so -

<nav class="vertical">
    <ul>
      <li>
        <a href="#">Home</a>
	  </li>
	   <li>
        <a href="#">Blog</a>
	  </li>
	   <li>
        <a href="#">Work</a>
	  </li>
	</ul>
</nav>

And the CSS is as follows -

nav.vertical {
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,.15);
  overflow: hidden;
  text-align: center;
}

  nav.vertical > ul {
    list-style-type: none;
  }

    nav.vertical > ul > li {
      display: block;
    }

Important style definitions -

  • border-radius - border-radius provides the rounded corners for our element
  • box-shadow - This adds a drop shadow to our element. Format as follows - Y value, X value, shadow size, color.
  • overflow - as our element contains other elements, we need to hide the contents if they extend outside the container. This ensures the rounded corners work as expected.

That gives us our basic HTML 5 vertical menu container. Next we need to style the main nav elements, which can be done by styling the anchor <a> elements -

nav.vertical > ul > li > a {
	background-color: rgb(157, 34, 60);
	background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	border-bottom: 1px solid rgba(255,255,255,.1);
	box-shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 1px 1px rgba(0,0,0,.1);
	color: rgb(255,255,255);
	display: block;
	font-size: .85rem;
	font-weight: 500;
	height: 50px;
	letter-spacing: .5rem;
	line-height: 50px;
	text-shadow: 0 1px 1px rgba(0,0,0,.1);
	text-transform: uppercase;
	transition: all .1s ease;
	text-decoration: none;
}

	nav.vertical > ul > li > a:hover {
		background-color: rgb(114, 51, 98);
		background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
		background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
		background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
		background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
		cursor: pointer;
	}

There's a lot going on in both of these definitions. First of all let's go through the basic anchor style -

  • background-color - used as back-up incase the gradient background isn't supported
  • background-image - prefixed for different browsers, this specifies the CSS 3 gradient effect on each main nav element
  • border-bottom - a simple 1 pixel line at the bottom of the element. Using RGBA makes the white line have 10% opacity, making it blend better
  • box-shadow - an inset box-shadow allows us to have a second border within the element, adding a nicer effect
  • color - white text
  • display - block element fills the whole width. Required when specifying a height
  • font-size - using rem makes the font size relative to the default font-size, allowing for nicer scalability
  • font-weight - 500 is a regular font-weight, not bold, not light.
  • height - specify the height of the element, used with display: block;
  • letter-spacing - increases the space between the letters within the element
  • line-height - setting to the same as the height will place our text in the vertical center of the element - no need for padding
  • text-shadow - add a simple 10% opacity shadow below our text
  • text-transform - make our text all uppercase/capitals
  • transition - used for animation, this makes all changes animated for 100ms using the ease animation
  • text-decoration - remove the underline on our link

The second style definition is using the :hover selector, meaning it's only active when the use hovers over the specified element. This works well with our transition definition as it will animate the changes.

Sub Navigation Menu

To create the second set of links we simply embed a second list inside our first list. This is very simple and easy to do, just remember to maintain the integrity of the HTML elements.

Let's take the first menu item and add its sub menu. This is done like so -

<ul>
  <li>
	<a href="#">Home</a>
	<!--START SUB MENU-->
	<div>
	  <ul>
		<li><a href="#">Index</a></li>
		<li><a href="#">About</a></li>
		<li><a href="#">Corporate</a></li>
		<li><a href="#">Contact</a></li>
	  </ul>
	</div>
	<!--END SUB MENU-->
  </li>
</ul>

I've commented the embedded list so you can see what's been added. The containing div isn't always needed when embedding lists, for this example it is as we're going to add a background color.

Let's look at styling the list. As our list is contained within another list, we can use the > CSS selector, making the CSS more specific.

  nav.vertical > ul > li > div {
	background-color: rgb(255,255,255);
  }

  nav.vertical > ul > li > div > ul {
	list-style-type: none;
  }

	nav.vertical > ul > li > div > ul > li > a {
	 background-color: rgb(255,255,255);
	 border-bottom: 1px solid rgba(0,0,0,.05);
	 color: #333331;
	 display: block;
	 font-size: 1.1rem;
	 padding: 10px 0;
	 text-decoration: none;
	 transition: all 0.15s linear;
	}

Most of the above code is self explanatory. It can be broken down like so -

  • Set a white background behind our list
  • Turn off HTML bullet points
  • Style our sub-menu list items

Next we want to animate our sub-menu when the user hovers over a list-item. This is combined with our previously defined transition: all 0.15s linear; statement. If you want to change the type, or speed of animation then that's what you need to change.

nav.vertical > ul > li > div > ul > li:hover > a {
	background-color: lightBlue;
	color: rgb(255,255,255);
	padding: 10px 0 10px 50px;
}

To make the text slide to the right we simply add 50px padding to the left. Change the 50px value to suit the amount of sliding you wish to happen.

Simple HTML 5 Vertical Menu Code

We've completed the basic menu, here's the full code so far.

HTML

<div class="wrapper">
  <nav class="vertical">
    <ul>
      <li>
        <a href="#">Home</a>
        <div>
          <ul>
            <li><a href="#">Index</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Corporate</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </div>
      </li>
      <li>
        <a href="#">Blog</a>
        <div>
          <ul>
            <li><a href="#">Articles</a></li>
            <li><a href="#">Inspiration</a></li>
            <li><a href="#">Tutorials</a></li>
          </ul>
        </div>
      </li>
      <li>
        <a href="#">Work</a>
        <div>
          <ul>
            <li><a href="#">Client Login</a></li>
            <li><a href="#">Get Quote</a></li>
            <li><a href="#">Portfolio</a></li>
          </ul>
        </div>
      </li>
    </ul>
  </nav>
  </div>

CSS

* {
	margin: 0;
	padding: 0;
	outline: none;
	
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

body {
    background: #eee;
    color: #444;
    -webkit-font-smoothing: antialiased;
    font-family: 'Helvetica Neue', sans-serif;
    font-size: 20px;
    font-weight: 400;
    height: auto !important;
    height: 100%;
    min-height: 100%;
    text-rendering: optimizeLegibility;
}

div.wrapper {
  margin: 20px auto;
  width: 350px;
}

nav.vertical {
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,.15);
  overflow: hidden;
  text-align: center;
}

  nav.vertical > ul {
    list-style-type: none;
  }

    nav.vertical > ul > li {
      display: block;
    }

      nav.vertical > ul > li > a {
        background-color: rgb(157, 34, 60);
        background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        border-bottom: 1px solid rgba(255,255,255,.1);
        box-shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 1px 1px rgba(0,0,0,.1);
        color: rgb(255,255,255);
        display: block;
        font-size: .85rem;
        font-weight: 500;
        height: 50px;
        letter-spacing: .5rem;
        line-height: 50px;
        text-shadow: 0 1px 1px rgba(0,0,0,.1);
        text-transform: uppercase;
        transition: all .1s ease;
        text-decoration: none;
      }

        nav.vertical > ul > li > a:hover {
         background-color: rgb(114, 51, 98);
         background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
         cursor: pointer;
        }
        
          nav.vertical > ul > li > div {
            background-color: rgb(255,255,255);
          }
 
          nav.vertical > ul > li > div > ul {
            list-style-type: none;
          }

            nav.vertical > ul > li > div > ul > li > a {
             background-color: rgb(255,255,255);
             border-bottom: 1px solid rgba(0,0,0,.05);
             color: #333331;
             display: block;
             font-size: 1.1rem;
             padding: 10px 0;
             text-decoration: none;
             transition: all 0.15s linear;
            }

              nav.vertical > ul > li > div > ul > li:hover > a {
                background-color: lightBlue;
                color: rgb(255,255,255);
                padding: 10px 0 10px 50px;
              }

Animated, Mobile Friendly Vertical Navigation

With our next menu we're going to build upon the previous example, animating certain elements and tweaking some styles.

Here's what we're going to be creating -

See the Pen Animated CSS accordion menu by lawnch (@lawnch) on CodePen.

Most of the HTML is the same as the previous example, the only difference being the use of labels & inputs instead of anchor tags in our main navigation menu. The below code shows the difference between the two -

Before -

  <li>
	<a href="#">Home</a>
	<div>
	  <ul>
		<li><a href="#">Index</a></li>
		<li><a href="#">About</a></li>
		<li><a href="#">Corporate</a></li>
		<li><a href="#">Contact</a></li>
	  </ul>
	</div>
  </li>
		

After -

  <li>
	<label for="home">Home</label>
	<input type="radio" name="verticalMenu" id="home" />
	<div>
	  <ul>
		<li><a href="#">Index</a></li>
		<li><a href="#">About</a></li>
		<li><a href="#">Corporate</a></li>
		<li><a href="#">Contact</a></li>
	  </ul>
	</div>
  </li>
		

Very little change... but it changes the menu dramatically.

The Theory

Through CSS selectors we can style elements next to / proceeding other elements. By using this we can create a toggle menu using purely HTML and CSS. The theory for this is -

  • Use labels to select radio input buttons
  • Give the radio inputs the same name so only 1 can be selected at any one time
  • When the radio is selected then display the container element that follows
  • When the radio input isn't selected then hide the container element
  • Use the max-height definition to animate the container, making it expand in size

CSS Styling

First of all we need to change some of our previously used CSS. As we're using labels and inputs instead of anchor elements we need to modify the CSS rule. Incase you want to also use normal menu items (traditional links), we'll keep that definition as well.

  nav.vertical > ul > li > label,
  nav.vertical > ul > li > a {
	background-color: rgb(157, 34, 60);
	background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
	border-bottom: 1px solid rgba(255,255,255,.1);
	box-shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 1px 1px rgba(0,0,0,.1);
	color: rgb(255,255,255);
	display: block;
	font-size: .85rem;
	font-weight: 500;
	height: 50px;
	letter-spacing: .5rem;
	line-height: 50px;
	text-shadow: 0 1px 1px rgba(0,0,0,.1);
	text-transform: uppercase;
	transition: all .1s ease;
  }

	nav.vertical > ul > li > label:hover,
	nav.vertical > ul > li > a:hover {
	 background-color: rgb(114, 51, 98);
	 background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
	 background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
	 background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
	 background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
	 cursor: pointer;
	}

By seperating definitions with commas we can combine two definitions into one. For that reason there's no styling differences between the code above and the previous example.

Next we want to style our sub-menu container. First we need to hide the container when the radio isn't selected, then we need to display, and animate it once it's selected.

Additionally we want to hide the radio input. As the input works with labels, there's no need for the user to be able to see the input.

nav.vertical > ul > li > label + input {
  display: none;
  visability: hidden;
}

  nav.vertical > ul > li > div {
	background-color: rgb(255,255,255);
	max-height: 0;
	overflow: hidden;
	transition: all .5s linear;
  }

	nav.vertical > ul > li > label + input:checked + div {
	  max-height: 500px;
	}

There are five important rules being used here -

  • + CSS 3 selector - this selector means following, ie.. "label + input" means "label followed by input
  • max-height - setting the max-height to 0 will automatically close all the divs when the page loads
  • Setting the div to overflow hidden will hide the content held inside the containing div
  • transition + max-height - by combining the transition and max-height styles we can give the impression the box is expanding
  • :checked CSS selector - this is for when the radio button is clicked / checked via the label

Full Code

With the above tweaks made the code should now look like the following -

HTML

<div class="wrapper">
  <nav class="vertical">
    <ul>
      <li>
        <label for="home">Home</label>
        <input type="radio" name="verticalMenu" id="home" />
        <div>
          <ul>
            <li><a href="#">Index</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Corporate</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </div>
      </li>
      <li>
        <label for="blog">Blog</label>
        <input type="radio" name="verticalMenu" id="blog" />
        <div>
          <ul>
            <li><a href="#">Articles</a></li>
            <li><a href="#">Inspiration</a></li>
            <li><a href="#">Tutorials</a></li>
          </ul>
        </div>
      </li>
      <li>
        <label for="work">Work</label>
        <input type="radio" name="verticalMenu" id="work" />
        <div>
          <ul>
            <li><a href="#">Client Login</a></li>
            <li><a href="#">Get Quote</a></li>
            <li><a href="#">Portfolio</a></li>
          </ul>
        </div>
      </li>
    </ul>
  </nav>
  </div>

CSS

* {
	margin: 0;
	padding: 0;
	outline: none;
	
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

body {
    background: #eee;
    color: #444;
    -webkit-font-smoothing: antialiased;
    font-family: 'Helvetica Neue', sans-serif;
    font-size: 20px;
    font-weight: 400;
    height: auto !important;
    height: 100%;
    min-height: 100%;
    text-rendering: optimizeLegibility
}

div.wrapper {
  margin: 20px auto;
  width: 350px;
}

nav.vertical {
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,.15);
  overflow: hidden;
  text-align: center;
}

  nav.vertical > ul {
    list-style-type: none;
  }

    nav.vertical > ul > li {
      display: block;
    }

      nav.vertical > ul > li > label,
      nav.vertical > ul > li > a {
        background-color: rgb(157, 34, 60);
        background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        border-bottom: 1px solid rgba(255,255,255,.1);
        box-shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 1px 1px rgba(0,0,0,.1);
        color: rgb(255,255,255);
        display: block;
        font-size: .85rem;
        font-weight: 500;
        height: 50px;
        letter-spacing: .5rem;
        line-height: 50px;
        text-shadow: 0 1px 1px rgba(0,0,0,.1);
        text-transform: uppercase;
        transition: all .1s ease;
      }

        nav.vertical > ul > li > label:hover,
        nav.vertical > ul > li > a:hover {
         background-color: rgb(114, 51, 98);
         background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
         cursor: pointer;
        }

        nav.vertical > ul > li > label + input {
          display: none;
          visability: hidden;
        }
        
          nav.vertical > ul > li > div {
            background-color: rgb(255,255,255);
            max-height: 0;
            overflow: hidden;
            transition: all .5s linear;
          }

            nav.vertical > ul > li > label + input:checked + div {
              max-height: 500px;
            }
 
          nav.vertical > ul > li > div > ul {
            list-style-type: none;
          }

            nav.vertical > ul > li > div > ul > li > a {
             background-color: rgb(255,255,255);
             border-bottom: 1px solid rgba(0,0,0,.05);
             color: #333331;
             display: block;
             font-size: 1.1rem;
             padding: 10px 0;
             text-decoration: none;
             transition: all 0.15s linear;
            }

              nav.vertical > ul > li > div > ul > li:hover > a {
                background-color: lightBlue;
                color: rgb(255,255,255);
                padding: 10px 0 10px 50px;
              }

Making Changes

Depending on how you want the vertical menu to behave you may decide to make some changes.

First of all you may decide you want the different menus to be independent. That's easy, change the input types from "radio" to "checkbox".

Secondly, you could add different groupings of menus by adding multiple radio input names, that way you could have 2/3/4 groupings across 4/6/8 menus.

HTML 5 Content Menu

With the above code you may decide to create an in-content tab box where users can select different data. The changes required are very simple yet again.

Here's what we can create with some minor tweaks -

See the Pen CSS 3 animated content box by lawnch (@lawnch) on CodePen.

Firstly we need to expand our wrapper width. This is done purely through CSS.

div.wrapper {
  margin: 20px auto;
  width: 650px;
}

Next we want to set a default content area, so the box is "open" when users first see it. That's done by adding checked="true" to the radio button that controls the area you wish to display.

<input type="radio" checked="true" name="verticalMenu" id="home" />

Because the content is slightly different this time, we want to speed up the animation and alter the height of the viewable area.

nav.vertical > ul > li > div {
	background-color: rgb(255,255,255);
	height: 0;
	overflow: scroll;
	transition: all .35s ease; 
}

	nav.vertical > ul > li > label + input:checked + div {
		height: 200px;
	}

Instead of animating the maximum height like before, we're animating the actual height. If the content inside the container is too big then we've set it to scroll, making it look like a traditional HTML frame.

Styling the Scrollbar with CSS

Finally we can style the webkit scrollbar with CSS. That means it works in Chrome and Safari.

The code is as follows -

nav.vertical ::-webkit-scrollbar {
	width: .9rem;
}

	nav.vertical ::-webkit-scrollbar-thumb {
		background-color: rgb(114, 51, 98);
		border: solid rgb(255,255,255);
		border-radius: 0 .4rem .4rem 0;
		border-width: .4rem .4rem .4rem 0;
	}

Have a play around with the widths and colors to get the look and feel that you want.

Finally you can add whatever content you like into the containing elements.

Code

My final code is included below.

HTML

<div class="wrapper">
  <nav class="vertical">
    <ul>
      <li>
        <label for="home">Home</label>
        <input type="radio" checked="true" name="verticalMenu" id="home" />
        <div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium magna ac nulla laoreet fringilla. Pellentesque pharetra elit feugiat erat ornare eleifend. Morbi lobortis risus quis semper consectetur. Vestibulum vulputate, lorem et tempor luctus, nisi tellus fermentum erat, ut imperdiet nunc justo ac odio. In ac sem erat. Suspendisse euismod faucibus dolor vel sodales. Donec sed placerat erat. Nulla facilisi. In in ipsum nunc. Maecenas at arcu nec justo lobortis vulputate quis a neque.</p>
           <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium magna ac nulla laoreet fringilla. Pellentesque pharetra elit feugiat erat ornare eleifend. Morbi lobortis risus quis semper consectetur. Vestibulum vulputate, lorem et tempor luctus, nisi tellus fermentum erat, ut imperdiet nunc justo ac odio. In ac sem erat. Suspendisse euismod faucibus dolor vel sodales. Donec sed placerat erat. Nulla facilisi. In in ipsum nunc. Maecenas at arcu nec justo lobortis vulputate quis a neque.</p>
        </div>
      </li>
      <li>
        <label for="blog">Blog</label>
        <input type="radio" name="verticalMenu" id="blog" />
        <div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium magna ac nulla laoreet fringilla. Pellentesque pharetra elit feugiat erat ornare eleifend. Morbi lobortis risus quis semper consectetur. Vestibulum vulputate, lorem et tempor luctus, nisi tellus fermentum erat, ut imperdiet nunc justo ac odio. In ac sem erat. Suspendisse euismod faucibus dolor vel sodales. Donec sed placerat erat. Nulla facilisi. In in ipsum nunc. Maecenas at arcu nec justo lobortis vulputate quis a neque.</p>
           <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium magna ac nulla laoreet fringilla. Pellentesque pharetra elit feugiat erat ornare eleifend. Morbi lobortis risus quis semper consectetur. Vestibulum vulputate, lorem et tempor luctus, nisi tellus fermentum erat, ut imperdiet nunc justo ac odio. In ac sem erat. Suspendisse euismod faucibus dolor vel sodales. Donec sed placerat erat. Nulla facilisi. In in ipsum nunc. Maecenas at arcu nec justo lobortis vulputate quis a neque.</p>
        </div>
      </li>
      <li>
        <label for="work">Work</label>
        <input type="radio" name="verticalMenu" id="work" />
        <div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium magna ac nulla laoreet fringilla. Pellentesque pharetra elit feugiat erat ornare eleifend. Morbi lobortis risus quis semper consectetur. Vestibulum vulputate, lorem et tempor luctus, nisi tellus fermentum erat, ut imperdiet nunc justo ac odio. In ac sem erat. Suspendisse euismod faucibus dolor vel sodales. Donec sed placerat erat. Nulla facilisi. In in ipsum nunc. Maecenas at arcu nec justo lobortis vulputate quis a neque.</p>
           <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pretium magna ac nulla laoreet fringilla. Pellentesque pharetra elit feugiat erat ornare eleifend. Morbi lobortis risus quis semper consectetur. Vestibulum vulputate, lorem et tempor luctus, nisi tellus fermentum erat, ut imperdiet nunc justo ac odio. In ac sem erat. Suspendisse euismod faucibus dolor vel sodales. Donec sed placerat erat. Nulla facilisi. In in ipsum nunc. Maecenas at arcu nec justo lobortis vulputate quis a neque.</p>
        </div>
      </li>
    </ul>
  </nav>
</div>

CSS

* {
	margin: 0;
	padding: 0;
	outline: none;
	
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

body {
    background: #eee;
    color: #444;
    -webkit-font-smoothing: antialiased;
    font-family: 'Helvetica Neue', sans-serif;
    font-size: 20px;
    font-weight: 400;
    height: auto !important;
    height: 100%;
    min-height: 100%;
    text-rendering: optimizeLegibility
}

div.wrapper {
  margin: 20px auto;
  width: 650px;
}

nav.vertical {
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,.15);
  overflow: hidden;
  text-align: center;
}

  nav.vertical > ul {
    list-style-type: none;
  }

    nav.vertical > ul > li {
      display: block;
    }

      nav.vertical > ul > li > label,
      nav.vertical > ul > li > a {
        background-color: rgb(157, 34, 60);
        background-image: -webkit-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: -moz-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: -o-linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        background-image: linear-gradient(135deg, rgb(114, 51, 98), rgb(157, 34, 60));
        border-bottom: 1px solid rgba(255,255,255,.1);
        box-shadow: inset 0 1px 1px rgba(0,0,0,.1), 0 1px 1px rgba(0,0,0,.1);
        color: rgb(255,255,255);
        display: block;
        font-size: .85rem;
        font-weight: 500;
        height: 50px;
        letter-spacing: .5rem;
        line-height: 50px;
        text-shadow: 0 1px 1px rgba(0,0,0,.1);
        text-transform: uppercase;
        transition: all .1s ease;
      }

        nav.vertical > ul > li > label:hover,
        nav.vertical > ul > li > a:hover {
         background-color: rgb(114, 51, 98);
         background-image: -webkit-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: -moz-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: -o-linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98));
         background-image: linear-gradient(150deg, rgb(114, 51, 98), rgb(114, 51, 98)); 
         cursor: pointer;
        }

        nav.vertical > ul > li > label + input {
          display: none;
          visability: hidden;
        }
        
          nav.vertical > ul > li > div {
            background-color: rgb(255,255,255);
            height: 0;
            overflow: scroll;
            transition: all .35s ease;
          }

            nav.vertical > ul > li > div > p {
              margin: 24px;
              text-align: left;
            }

            nav.vertical ::-webkit-scrollbar {
              width: .9rem;
            }

            nav.vertical ::-webkit-scrollbar-thumb {
              background-color: rgb(114, 51, 98);
              border: solid rgb(255,255,255);
              border-width: .4rem .4rem .4rem 0;
              border-radius: 0 .4rem .4rem 0;
            }

            nav.vertical > ul > li > label + input:checked + div {
              height: 200px;
            }

Conclusion

Thanks for reading this tutorial. If you have any questions or want to show where you've used any of the examples, please post below.

Advertisement
You may also like:
comments powered by Disqus