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.
@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;
}
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')
}
}
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