css Responsive menu
Html:---
<link rel="stylesheet" href="style/menuresp.css">
</head>
<body>
<div class="container">
<div class="header">
<div class="title">
<h1>Premium</h1>
</div>
<!-- adding responsiveness -->
<a href="#" class="togglebutton">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<!------>
<div class="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Profile</a></li>
</ul>
</div>
</div>
</div>
<script src="script/respmenu.js"></script>
</body>
</html>
css:--
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
.container {
height: 100vh;
width: 100vw;
background-color: aqua;
}
.header {
width: 100vw;
/* height: 20vh; */
background-color: blue;
display: flex;
justify-content: space-between;
align-items: center;
color: white;
}
.title {
width: 30vw;
/* height: 20vh; */
background-color: burlywood;
}
.menu {
width: 50vw;
/* height: 20vh; */
background-color: cadetblue;
}
.menu ul {
display: flex;
}
.menu li {
list-style-type: none;
}
.menu li a {
text-decoration: none;
color: white;
padding: 1em;
display: block;
/*larger in size*/
}
.menu li :hover {
background-color: grey;
}
.togglebutton {
position: absolute;
/*right side
of the element */
top: .75rem;
right: 1rem;
/* display: flex; */
display: none;
flex-direction: column;
justify-content: space-between;
width: 30px;
height: 21px;
/* background-color: red; */
}
.togglebutton .bar {
height: 5px;
width: 100%;
background-color: white;
border-radius: 10px;
/* background-color: white; */
/* border-radius:20px; */
}
@media screen and (max-width:576px) {
.header {
background-color: gold;
flex-direction: column;
}
.title {
background-color: greenyellow;
width: 100vw;
}
.menu {
background-color: hotpink;
width: 100vw;
}
.togglebutton {
display: flex;
}
.menu {
flex-direction: column;
align-items: flex-start;
display: none;
width: 100%;
}
.menu ul {
flex-direction: column;
width: 100%;
}
.menu li {
text-align: center;
}
.menu li a {
padding: .5rem 1rem;
}
.menu.active {
display: flex;
}
}
js:--
const togglebutton = document.
getElementsByClassName('togglebutton')[0];
const menu = document.getElementsByClassName
('menu')[0];
togglebutton.addEventListener('click', () =>
{
menu.classList.toggle('active')
})
Comments
Post a Comment