Responsive Sidebar Menu with CSS and JavaScript

Responsive Sidebar Menu with CSS and JavaScript

In this tutorial we will see how to make a Responsive Sidebar Menu with CSS and JavaScript. Pure CSS and JavaScript is used for this purpose, complete code is given.

HTML Code

Take a look at the HTML code given below.

<div id="menu" class="menu">
<a href="javascript:void(0)" class="close" onclick="closeMenu()">✖</a>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">FAQ</a>
<a href="#">Contact</a>
</div>

<span onclick="openMenu()">Menu</span>

CSS Code

CSS code is given below.

<style>
body
{
font-family: 'Barlow Condensed', sans-serif;
}
.menu {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 0;
max-width: 200px;
z-index: 1;
background-color: #63029c;
overflow-x: hidden;
padding-top: 10px;
transition: 0.5s;
}
.menu a {
padding: 15px 25px;
text-decoration: none;
font-size: 25px;
color: #FFF;
display: block;
transition: 0.3s;
}
.menu a:hover {
color: #F2F2F2;
}
.menu .close {
font-size: 15px;
text-align: right;
}
@media screen and (max-width: 450px) {
.menu {max-width: 100%;}
}
@media screen and (max-height: 400px) {
.menu {padding-top: 5px;}
.menu a {font-size: 18px;}
}
</style>

JavaScript Code

Take a look at the JavaScript Code given below.

<script>
function openMenu() {
document.getElementById("menu").style.width = "100%";
}

function closeMenu() {
document.getElementById("menu").style.width = "0";
}
</script>

Video Tutorial

Watch our video tutorial on Responsive Sidebar Menu with CSS and JavaScript.

Comments

Popular posts from this blog

Gove confirms mandatory housebuilding targets for councils will be abolished in face of Tory rebellion – UK politics live

Kotak Mahindra Bank Recruitment 2022 Released for Graduate Candidates And Apply Online