Responsive Sticky Navigation Bar with Hero Section using HTML, CSS & JavaScript

Responsive Sticky Navigation Bar with Hero Section using HTML, CSS & JavaScript

Hello developers, today in this blog, you'll learn how to create a Responsive Sticky Navigation Bar with Hero Section using HTML, CSS & JavaScript.

A sticky navigation bar on the webpage remains fixed and visible in the same position as the user scrolls down and moves about the website, that is it gets fixed in the webpage. It remains in the same place even when the user scrolls the page down the website. The navbar or navigation bar remains stick to the place, so only it is called a sticky navbar or sticky navigation bar. The navigation bar is mostly used in all the websites, whereas the sticky navigation bar is used only in some of the websites. A hero section is a full-screen section that consists of a background image, or video, or illustrations, or animations, with some text.

In this blog(Responsive Sticky Navigation Bar with Hero Section), at first, on the webpage, there is a navbar at the top right of the webpage. The navbar or the navigation bar contains brand on the top left and home, about, service, and contact on the top right of the webpage. When you hover over those texts, the color of the text changes from white to violet color. When you scroll on the webpage the navbar or navigation bar remains fixed at the same place.

The source code of this Responsive Sticky Navigation Bar with Hero Section using HTML, CSS & JavaScript is given below, if you want the source code of this program, you can copy it. You can use this code of Responsive Sticky Navigation Bar with Hero Section with your creativity and, can take this project to the next level.

Responsive Sticky Navigation Bar with Hero Section [Source Code]

To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html, and remember, you have to create a file with a .html extension.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="style.css" /> <title>Sticky Nav / hero dection || learningrobo</title> </head> <body> <nav class="nav"> <div class="container"> <h1 class="logo"><a href="/index.html">BRAND</a></h1> <ul> <li><a href="#" class="current">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Services</a></li> <li><a href="#">Contact</a></li> </ul> </div> </nav> <div class="hero"> <div class="container"> <h1>Welcome To LearningRobo</h1> <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores, consequuntur?</p> </div> </div> <section class="container content"> <h2>Sample content</h2> <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ratione dolorem voluptates eveniet tempora ut cupiditate magnam, sapiente, hic quo in ipsum iste soluta eaque perferendis nihil recusandae dolore officia aperiam corporis similique. Facilis quos tempore labore totam! Consectetur molestiae iusto ducimus error reiciendis aspernatur dolor, modi dolorem sit architecto, voluptate magni sunt unde est quas? Voluptates a dolorum voluptatum quo perferendis aut sit. Aspernatur libero laboriosam ab eligendi omnis delectus earum labore, placeat officiis sint illum rem voluptas ipsum repellendus iste eius recusandae quae excepturi facere, iure rerum sequi? Illum velit delectus dicta et iste dolorum obcaecati minus odio eligendi!</p> <h3>Sample content</h3> <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Pariatur provident nostrum possimus inventore nisi laboriosam consequatur modi nulla eos, commodi, omnis distinctio! Maxime distinctio impedit provident, voluptates illo odio nostrum minima beatae similique a sint sapiente voluptatum atque optio illum est! Tenetur tempora doloremque quae iste aperiam hic cumque repellat?</p> </section> <div class="credit">Made with <span style="color:tomato">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> <script src="script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and, remember that you have to make a file with a .css extension.


@import url('https://fonts.googleapis.com/css?family=Open+Sans');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Open Sans', sans-serif;
  padding-bottom: 50px;
  background: #202124;

}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

.nav {
  position: fixed;
  background-color: #000;
  top: 0;
  left: 0;
  right: 0;
  transition: all 0.3s ease-in-out;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.nav .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  transition: all 0.3s ease-in-out;
}

.nav ul {
  display: flex;
  list-style-type: none;
  align-items: center;
  justify-content: center;
}

.nav a {
  color: #fff;
  text-decoration: none;
  padding: 7px 15px;
  transition: all 0.3s ease-in-out;
}

.nav.active {
  background-color: #000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.nav.active a {
  color: #fff;
}

.nav.active .container {
  padding: 10px 0;
}

.nav a.current,
.nav a:hover {
  color: #887fff;
  font-weight: bold;
}

.hero {
  background-image: url('https://cdn.pixabay.com/photo/2021/07/03/16/04/sunrise-6384297__480.png');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: bottom center;
  height: 100vh;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  position: relative;
  margin-bottom: 20px;
  z-index: -2;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.1);
  z-index: -1;
}

.hero h1 {
  font-size: 46px;
  margin: -20px 0 20px;
  background-color: #12192c;
  color:#887fff;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}



.content h2,
.content h3 {
    color: #fff;
  font-size: 150%;
  margin: 20px 0;
}

.content p {
  color: #fff;
  line-height: 30px;
  letter-spacing: 1.2px;
}

.credit a{
    text-decoration: none;
    color: #887fff;
  }

  .credit {
      color:#fff;
      margin-top: 10px;
      text-align: center;
  }
JavaScript makes the page work functionally which makes the image to be active on clicking. At last, create a JavaScript file with the name of script.js and, remember that you've got need to make a file with a .js extension.


const nav = document.querySelector('.nav')
window.addEventListener('scroll', fixNav)

function fixNav() {
    if(window.scrollY > nav.offsetHeight + 150) {
        nav.classList.add('active')
    } else {
        nav.classList.remove('active')
    }
}
We hope you would like this Responsive Sticky Navigation Bar with Hero Section using HTML, CSS & JavaScript.

Thank you for reading our blog. If you face any problem in creating this Responsive Sticky Navigation Bar with Hero Section using HTML, CSS & JavaScript, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.

Thank you
Learning robo team

Post a Comment

Thank you
Learning robo team

Post a Comment (0)

Previous Post Next Post
Learning Robo says...
code copied
Welcome