Vertical menu bars in HTML and CSS

Vertical menu bars

Vertical menu bars are used in sites to show labels and more options on the one side of the web page. The vertical navigation bar is used when we want the information will show only if user click on menu button mostly it’s done on mobile sites but nowadays it is also trending on screen web pages.

 

Call a method on Image Click

So to create vertical menu bar first, we create a header div. Inside that header put a menu logo which will easily be available on the internet.

 

Specify Menu Items as Paragraph Elements

As in above code, we have an onclick event in our image tag its because we want some action when a user clicks on menu image.

Now to create vertical navigation menu bar the code is following:

When creating the menu bar we use anchors and list items, in this case, we can put anchors on our paragraphs. To link to other pages.

The above code is for vertical menu bar containing different menus like home, about, etc. I bound them in a menubar div.

Body of HTML Page

Create a body area where all other content will show.

 

Apply CSS Properties

To style this, I target all these items by their ids and classes.

 

Method to be Called onClick

In above code, its simple but one thing I put menu bar display is equal to none (display: none 😉. I do this because I want to show it on user click only now to show it on user click the JavaScript code is:

Above code is a simple function that is the handler for the onclick event, and it checks if the menu bar is not displayed, display it and if it is displayed already then hides it.

View live demo of Slide in and slide out menu

Download HTML file of slide in slide out menu