Responsive navbar:
Here we are creating a responsive navbar for all devices with pure CSS and HTML. A responsive design is basically about using HTML and CSS to automatically resize, shrink, hide, enlarge a website to make it look good and attractive on all devices (Desktop, tablets, phones).
like this:
watch detailed video:
source code :
html code:
<!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">
<title>Navbar</title>
<link rel="stylesheet" href="navbarstyle2.css">
<script src="https://kit.fontawesome.com/52244c391d.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<span id="ham-btn">
<i class="fas fa-bars"></i>
</span>
<img src="logo.jpg" alt="" id="logo">
<nav class="menu">
<span class="nave"><i class="fas fa-home"></i> home<div class="line"></div></span>
<span class="nave"><i class="fas fa-user"></i> about<div class="line"></div></span>
<span class="nave"><i class="fas fa-chalkboard-teacher"></i> services<div class="line"></div></span>
<span class="nave"><i class="fas fa-book"></i> blog<div class="line"></div></span>
<span class="nave"><i class="fas fa-phone-alt"></i> contact<div class="line"></div></span>
</nav>
<span>
<input type="checkbox" name="" id="search-btn-control">
<label for="search-btn-control">
<input type="search" name="" id="search">
<i class="fas fa-search"></i>
</label>
</span>
</div>
<script>
console.log("checking");
let hambtn = document.getElementById("ham-btn");
hambtn.addEventListener("click",()=>{
let menu = document.querySelector(".menu");
menu.classList.toggle("show");
})
</script>
</body>
</html>
css code:
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap');
*{
margin: 0;
padding: 0;
}
html{
font-size: 62.5%;
}
body{
width: 100vw;
height: 100vh;
background-image: url("computer3.jpg");
background-repeat: no-repeat;
background-size: 100vw 100vh;
background-position: center;
}
.container{
display: flex;
justify-content: space-around;
align-items: center;
box-sizing: border-box;
color: white;
background-color: rgba(3,34,46);
}
.menu{
display: flex;
width: 60%;
align-items: center;
justify-content: space-around;
}
#logo{
height: 5rem;
margin: 4px 0 ;
border-radius: 100%;
}
.nave{
margin: 0 2rem;
font-size: 1.7rem;
text-transform: uppercase;
cursor: pointer;
font-family: "Bebas Neue";
transition: all 1s;
}
.nave:hover{
letter-spacing: .2rem;
transition: all 1s;
}
.line{
width: 0%;
height: .12rem;
background-color: white;
transition: all 1s;
}
.nave:hover .line{
width: 100%;
}
#search{
width: 0px;
outline: none;
transition: all 1s;
}
#search-btn-control{
display: none;
}
.fa-search{
font-size: medium;
cursor: pointer;
}
#search-btn-control:checked + label > #search{
width: 15rem;
}
.fa-bars{
display: none;
font-size: x-large;
}
@media screen and (max-width:710px){
.menu{
display: flex;
flex-direction: column;
position: fixed;
background-color: #0e2a35;
justify-content: unset;
width: 100%;
height: 100%;
top: 5.6rem;
left: -100%;
transition: all 1s;
}
.show{
left: 0%;
}
.nave{
margin-top: 3rem;
font-size: 2rem;
}
.fa-bars{
display: inline-block;
}
}


0 Comments