Create Side Navigation bar with HTML and CSS

Welcome back Guys!
Today I’m going to show you how easily you can create a side navigation bar with using simple HTML and basic CSS. So let’s get started with HTML part.

Reference Video:

<html lang=”en”>
<head>
<meta charset=…


This content originally appeared on DEV Community and was authored by Rohit Sharma

Welcome back Guys!
Today I'm going to show you how easily you can create a side navigation bar with using simple HTML and basic CSS. So let's get started with HTML part.

Reference Video:

<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>Sticky Side Navigation Bar</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="nav-bar">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Pricing</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>
    </div>
    <div class="content">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptate, quibusdam est tempora sint repellendus impedit expedita obcaecati sapiente, eligendi nobis praesentium quidem aliquam earum explicabo dicta veniam sunt reprehenderit nemo hic et itaque nulla a? Unde, id. Officiis suscipit excepturi impedit provident cumque, sunt necessitatibus ad nobis nesciunt commodi, labore voluptates repellat? Aliquam, suscipit et recusandae, atque delectus unde ab veniam quam commodi aut eum dolore dicta adipisci fugit quas animi obcaecati harum voluptatem? Ad voluptatum, rerum adipisci dolorum culpa molestiae error vero. Nemo laudantium necessitatibus praesentium dignissimos sint similique pariatur rerum vitae officia vero earum facere, molestiae cumque? Quisquam.
    </div>
    <script src="main.js"></script>
</body>
</html>

We added 4 random links in div tag class (nav-bar) and dummy text in another div tag class (content). And that's enough for HTML.
And now it's time to jump into the most important part i.e. CSS.

      *{
        box-sizing: border-box;
        }
        html,body{
            margin: 0;
            padding: 0;
        }
        .nav-bar{
            background: lightgray;
            width: 30%;
            height: 100%;
            position: fixed;
            top: 0;
            left: 0;
            overflow-y: auto;
        }
        .nav-bar a{
            text-decoration: none;
            color: red;
            display: block;
        }
        .nav-bar ul{
            list-style-type: none;
            margin: 0;
            padding: 0;
        }
        .nav-bar ul li a{
            padding: 10px;
            background: lightgray;

        }

        .nav-bar ul li a:hover{
            background: #173459;
        }
        .nav-bar li{
            border-bottom: 1px solid #333;
        }
        .nav-bar li:last-child{
            border: none;
        }
        .content{
            margin-left: 30%;
            width: 70%;
            padding: 2%;
        }

Important Note:-
• In class "nav-bar" we set width of the nav-bar 30% so it covers only 30% of screen.
• We set overflow-Y to auto. So, if content amount increases then there will be a slide-bar.
• Now for content we set margin-left: 30% because in that 30% part we want to display the navigation bar.
• And set width: 70% so that remaining part is covered by the content.
That's it. We just created a sticky side Navigation Bar using basic HTML and CSS.

I Hope you loved ♥ it ☻


This content originally appeared on DEV Community and was authored by Rohit Sharma


Print Share Comment Cite Upload Translate Updates
APA

Rohit Sharma | Sciencx (2021-11-28T14:09:20+00:00) Create Side Navigation bar with HTML and CSS. Retrieved from https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/

MLA
" » Create Side Navigation bar with HTML and CSS." Rohit Sharma | Sciencx - Sunday November 28, 2021, https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/
HARVARD
Rohit Sharma | Sciencx Sunday November 28, 2021 » Create Side Navigation bar with HTML and CSS., viewed ,<https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/>
VANCOUVER
Rohit Sharma | Sciencx - » Create Side Navigation bar with HTML and CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/
CHICAGO
" » Create Side Navigation bar with HTML and CSS." Rohit Sharma | Sciencx - Accessed . https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/
IEEE
" » Create Side Navigation bar with HTML and CSS." Rohit Sharma | Sciencx [Online]. Available: https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/. [Accessed: ]
rf:citation
» Create Side Navigation bar with HTML and CSS | Rohit Sharma | Sciencx | https://www.scien.cx/2021/11/28/create-side-navigation-bar-with-html-and-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.