Create a Sidebar Menu

Created on May 16th, 2015

Have you ever needed to have a sidebar menu in your site? Well, you're in luck because this video will show you step-by-step just how easy it is to create a sidebar menu with HTML, CSS, and a little bit of jQuery. Here is the HTML code you will need below:

<!DOCTYPE html>
<html>
<head>
	<title>SideBar Menu</title>
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

	<div id="sidebar">

		<ul>
			<li><a href="#">Link 1</a></li>
			<li><a href="#">Link 2</a></li>
			<li><a href="#">Link 3</a></li>
			<li><a href="#">Link 4</a></li>
			<li><a href="#">Link 5</a></li>
		</ul>

		<div id="sidebar-btn">
			<span></span>
			<span></span>
			<span></span>
		</div>

	</div>

	

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	<script>

	$(document).ready(function(){
		$('#sidebar-btn').click(function(){
			$('#sidebar').toggleClass('visible');
		});
	});

	</script>

</body>
</html>

And here are the CSS styles from the video:

body{
	margin:0px;
	padding:0px;
	font-family:"Helvetica Neue", Helvetica, Arial;
}

#sidebar{
	background:#151718;
	width:200px;
	height:100%;
	display:block;
	position:absolute;
	left:-200px;
	top:0px;
	transition:left 0.3s linear;
}

#sidebar.visible{
	left:0px;
	transition:left 0.3s linear;
}

ul{
	margin:0px;
	padding:0px;
}

ul li{
	list-style:none;
}

ul li a{
	background:#1C1E1F;
	color:#ccc;
	border-bottom:1px solid #111;
	display:block;
	width:180px;
	padding:10px;
	text-decoration: none;
}

#sidebar-btn{
	display:inline-block;
	vertical-align: middle;
	width:20px;
	height:15px;
	cursor:pointer;
	margin:20px;
	position:absolute;
	top:0px;
	right:-60px;
}

#sidebar-btn span{
	height:1px;
	background:#111;
	margin-bottom:5px;
	display:block;
}

#sidebar-btn span:nth-child(2){
	width:75%;
}

#sidebar-btn span:nth-child(3){
	width:50%;
}

Checkout a live example of this functionality here: https://codepen.io/devdojo/pen/PqzzOK.

Comments (0)