how to create responsive navbar with pure css.

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');
*{
    margin0;
    padding0;
}
html{
font-size62.5%;

}
body{
    width100vw;
    height100vh;
    background-imageurl("computer3.jpg");
    background-repeatno-repeat;
    background-size100vw 100vh;
    background-positioncenter;

}
.container{
    displayflex;
    justify-contentspace-around;
    align-itemscenter;
    box-sizingborder-box;
    colorwhite;
    background-colorrgba(3,34,46);
}
.menu{
    displayflex;
    width60%;
    align-itemscenter;
    justify-contentspace-around;

}
#logo{
    height5rem;
    margin4px 0 ;
    border-radius100%;

}
.nave{
    margin0 2rem;
    font-size1.7rem;
    text-transformuppercase;
    cursorpointer;
    font-family"Bebas Neue";
    transitionall 1s;
}
.nave:hover{
    letter-spacing.2rem;
    transitionall 1s;
}
.line{
    width0%;
    height.12rem;
    background-colorwhite;
    transitionall 1s;
}
.nave:hover .line{
    width100%;
}
#search{
    width0px;
    outlinenone;
    transitionall 1s;
}
#search-btn-control{
    displaynone;
}
.fa-search{
    font-sizemedium;
    cursorpointer;
}
#search-btn-control:checked + label > #search{
    width15rem;
}
.fa-bars{
    displaynone;
    font-sizex-large;
}

@media screen and (max-width:710px){
    .menu{
        displayflex;
        flex-directioncolumn;
        positionfixed;
        background-color#0e2a35;
        justify-contentunset;
        width100%;
        height100%;
        top5.6rem;
        left-100%;
        transitionall 1s;
    }
    .show{
        left0%;
    }
    .nave{
        margin-top3rem;
        font-size2rem;
    }
    .fa-bars{
        displayinline-block;
    }
    
}



used images:


Post a Comment

0 Comments