Create Responsive Navigation Bar Tutorial (HTML & CSS grid)
HTML file (menu.html):-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="menu.css">
<title>Document</title>
</head>
<body>
<header>
<div class="container">
<nav class="nav_checkbox">
<a href="#" class="logo"><h2>LOGO</h2></a>
<input type="checkbox" id="tab-nav" class="tab-nav">
<label for="tab-nav" class="label">
<div class="burger"></div>
<div class="burger"></div>
<div class="burger"></div>
</label>
<ul class="content_nav">
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT</a></li>
<li><a href="#">BLOG</a></li>
<li><a href="#">SERVICE</a></li>
<li><a href="#">LOGIN</a></li>
</ul>
</nav>
</div>
</header>
<section class="content_section">
</section>
</body>
</html>
CSS file (menu.css):-
body{
margin: 0;
padding: 0;
box-sizing: border-box;
}
header{
position: fixed;
top: 0;
z-index: 1;
width: 100%;
background-color: rgba(0, 0, 0, 0.404);
}
.container{
width: 1280px;
margin: auto;
}
.nav_checkbox{
display: grid;
grid-template-columns: 1fr 1fr;
align-items: center;
padding: 10px 0px;
}
.logo{
text-decoration: none;
color: white;
padding-left: 10px;
}
.tab-nav{
outline: none;
display: none;
}
.label{
display: none;
color: white;
}
.burger{
width: 35px;
height: 5px;
background-color: white;
margin-top: 5px;
}
.content_nav{
grid-column: 3;
list-style: none;
margin: 0;
padding: 0;
}
.content_nav li{
display: inline-block;
padding-right: 10px;
}
.content_nav li a{
text-decoration: none;
color: white;
position: relative;
}
.content_nav li a::after{
content: '';
display: block;
height: 2px;
background-color: white;
position: absolute;
left: 0;
right: 0;
transform-origin: right;
transform: scale(0, 1);
transition: transform ease-in-out 0.5s;
}
.content_nav li a:hover::after{
transform: scale(1, 1);
}
.content_section{
height: 120vh;
background-image: url(back.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: grid;
justify-items: center;
align-items: center;
}
@media screen and (max-width: 1280px){
.container{
width: 100%;
}
}
@media screen and (max-width: 770px){
.label{
display: grid;
cursor: pointer;
grid-column: 3;
padding-right: 10px;
}
.content_nav{
display: grid;
grid-template-columns: 1fr;
grid-column: 1/4;
text-align: center;
max-height: 0;
overflow: hidden;
transition: all ease-in-out 0.6s;
}
.nav_checkbox input:checked ~ .content_nav{
max-height: 500px;
}
.content_nav li{
padding: 15px 0px;
}
}
background-image:-
channel link :- https://www.youtube.com/channel/UC1DFWpD1k1PtxIzYbdBAj6g
Add your comment
Signature :- Ayoub Shindi (Dev AAS).
Comments
Post a Comment