Responsive Navbar Using HTML , CSS and JAVASCRIPT

 Responsive Navbar Using HTML , CSS and JAVASCRIPT



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">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <title>Document</title>
</head>
<body>
    <nav id="menu" class="nav">
        <a href="#" class="active">Home</a>
        <a href="#">Course</a>
        <a href="#">Profile</a>
        <a href="#">Contact</a>
        <a href="javascript:void(0)" class="icon" onclick="show()">
            <i class="fa fa-bars"></i>
        </a>
    </nav>

    <script src="script.js"></script> 
</body>
</html>

CSS Code

*{
    margin:0;
}
body{
    background-color: cadetblue;
}

nav{
    background-color: black;
    overflow: hidden;
}

nav a{
    float: left;
    text-decoration: none;
    color:white;
    padding:14px 17px;
    background-color: red;
    font-size: 17px;
}
nav a:hover{
    background-color: white;
    color:red;
}
nav .active{
    background: blue;
}
nav .icon{
    display:none;
}

@media screen and (max-width:600px) {
    nav a:not(:first-child){
        display: none;
    }
    nav{
        position: relative;
    }
    nav a.icon{
        float: right;
        display: block;
        position: absolute;
        right: 0;
        top:0;
    }

    nav.responsive a{
        float: none;
        display:block;
    }
}

JavaScript Code

function show(){
    var x = document.getElementById("menu");
    
    if(x.className==="nav"){
        x.className += " responsive";
    }else{
        x.className="nav";
    }
}








Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Make a GST Calculator using HTML and JavaScript

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java