Navigation Bar in HTML-CSS | How to make a navbar in html and css in 3 easy steps -Codestarshub

Navigation Bar is a very important element of a website or a web page. It helps the user to easily locate and navigate through the website.


Navigation Bar is just a list of links

Navigation bars are just a group of lists ordered and styled using CSS.

We generally use unordered lists for navigation bars.


So lets begin:


STEP 1: Creating the layout


<!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>Document</title>
</head>
<body>
<div class="navbar">
    <nav>
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </nav>
</div>
    
</body>
</html>


STEP 2: 

Remove list-styling i.e remove bullets, Make the lists horizontal using flexbox.


<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>Document</title>
    <style>
        *{
            <!-- used to remove margin or padding between any element and the page-->
            margin:0
            padding0;
        }
        body {
            background-coloraqua;
        }

        .navbar{
            background-colorcrimson;
        }

        ul {
            positionrelative; <!-- makes it relative to the parent body i.e div -->
            left10%; <!-- shifts 10% from left -->
            displayflex; <!-- arranges in flexbox style i.e horizontally -->
        }

        li {
            list-stylenone;
            padding10px; <!-- adds padding between list items-->
        }
    </style>
</head>


STEP 3: 

Further styling

<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>Document</title>
    <style>
        *{

            margin:0
            padding0;
        }
        body {
            background-coloraqua;
        }

        .navbar{
            height:60px;
            background-colorcrimson;
        }

        ul {
            
            positionrelative;
            left10%;
            displayflex;
        }

        li {
            margin-top5px;
            list-stylenone;
            padding10px;
            font-family'Franklin Gothic Medium''Arial Narrow'Arialsans-serif;
            font-size20px;;
        }
        li:hover{
            cursorpointer;
            colorwheat;
            transition.4s;
            transformscale(1.2);
        }
    </style>
</head>

Preview:




Full 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>Document</title>
    <style>
        *{

            margin:0
            padding0;
        }
        body {
            background-coloraqua;
        }

        .navbar{
            height:60px;
            background-colorcrimson;
        }

        ul {
            
            positionrelative;
            left10%;
            displayflex;
        }

        li {
            margin-top5px;
            list-stylenone;
            padding10px;
            font-family'Franklin Gothic Medium''Arial Narrow'Arialsans-serif;
            font-size20px;;
        }
        li:hover{
            cursorpointer;
            colorwheat;
            transition.4s;
            transformscale(1.2);
        }
    </style>
</head>

<body>
    <div class="navbar">
        <nav>
            <ul>
                <li>Home</li>
                <li>About US</li>
                <li>Contact us</li>
                <li>Gallery</li>
            </ul>
        </nav>
    </div>

</body>

</html>








2 comments:

Powered by Blogger.