Pure Css Sticky Navigation Bar Design
A sticky navigation bar is a popular design element that gives a website a premium look. In our daily browsing, we come across numerous websites, each featuring different types of navigation bars or menus that enhance their visual appeal and usability. If you're interested in exploring various navigation bar designs, you can check out our related articles for inspiration.
In this article, we will learn how to create a sticky navigation bar using only HTML and CSS. A sticky navbar ensures that while the website content scrolls, the menu remains fixed at the top of the browser screen, improving accessibility and user experience. Although this effect can also be achieved using JavaScript and jQuery, this guide focuses solely on HTML and CSS. We will cover JavaScript-based navigation bars in a separate article.
Read Also:
01. HTML Code:
<!DOCTYPE html>
<html>
<head>
<title>Pure Css Sticky Navigation Bar | Rustcode</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<strong>main content.</strong>
</body>
</html>
We are also including an image in the blog card design. You can download that image from this github link.
02. Navigation Bar Structure:
<!DOCTYPE html>
<html>
<head>
<title>Pure Css Sticky Navigation Bar | Rustcode</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- Header Section -->
<div class="header">
<h3>Sticky Navigation Bar</h3>
</div>
<!-- Navigation Menu -->
<div class="menu">
<a href="#">HOME</a>
<a href="#">FEATURES</a>
<a href="#">BLOG</a>
<a href="#">ABOUT</a>
<a href="#">CONTACT</a>
</div>
<!-- Image Container -->
<div class="image-container">
<img src="image.jpg" class="image" alt="Navigation Bar Image"/>
</div>
<!-- Content Section -->
<div class="content">
<h2>Sticky Navigation Bar</h2>
<p>
Proin eget tristique arcu. Duis at metus laoreet, mattis dolor vel, pulvinar odio.
Integer ornare nisi ultrices tellus elementum ultricies. Interdum et malesuada fames
ac ante ipsum primis in faucibus. Duis vel tristique ipsum, in tempor lectus. Praesent
id odio ut ligula auctor ultrices nec eget ligula. Praesent varius nisi lacus, ut pretium
ligula pellentesque eu. Phasellus porttitor quis ipsum a venenatis. Mauris lobortis maximus
massa a congue.
</p>
</div>
</body>
</html>
Code Explanation:
<!DOCTYPE html>
- Declares that the document is an HTML5 file.<head>
Section - Defines metadata and includes an external CSS file (style.css
) for styling.<body>
Section - Contains the entire page content.- Header (
.header
) - Displays the website title as<h3>
inside adiv
to ensure styling flexibility. - Navigation Menu (
.menu
) - Contains multiple<a>
(anchor) links for navigation. - Image Section (
.image-container
) - Holds an image (image.jpg
) related to the content. - Content Section (
.content
) - Displays a heading (<h2>
) and a paragraph (<p>
) for additional information.
Output:
Read Also:
- Preloader Loading Animation | Html, Css And Gsap
- Social Media Buttons Animation With Rotation Hover Effect | Html & Css
- Pure CSS Progress Bar Animation | HTML And CSS
- Shining Effect On Text | HTML And CSS
- Show And Hide Password Animation | HTML, CSS And Javascript
- Simple Button Group Design | HTML And CSS
- Responsive Newsletter Subscription Form Design | HTML And CSS
- Responsive Price Table Design | HTML And CSS
03. CSS Styling:
body {
padding: 0;
margin: 0;
background: #e1e1e1;
}
/* Header Styling */
.header {
background: rgba(0, 0, 0, 0.9);
padding: 6px 24px;
text-align: left;
color: white;
letter-spacing: 1px;
font-size: 24px;
text-transform: uppercase;
}
/* Sticky Navigation Bar */
.menu {
position: sticky;
top: 0;
background-color: black;
margin: 0;
overflow: hidden;
}
/* Navigation Links */
.menu a {
font-family: Arial, sans-serif;
text-decoration: none;
font-size: 18px;
letter-spacing: 1px;
box-sizing: border-box;
float: left;
display: inline-block;
color: #f2f2f2;
text-align: center;
padding: 16px 24px;
}
/* Navigation Hover Effect */
.menu a:hover {
background: #ff9f1c;
color: black;
}
/* Image Container */
.image-container {
position: relative;
z-index: -1;
top: 0;
}
/* Image Styling */
.image-container img {
max-width: 100%;
max-height: 100vh;
}
/* Content Section */
.content {
padding: 0 24px;
text-align: justify;
font-size: 20px;
}
Code Explanation:
- Global Styles (
body
) - Removes default margin & padding and sets a light grey background (#e1e1e1
). - Header (
.header
) - Uses a dark background (rgba(0,0,0,0.9)
) for a sleek look, with white, uppercase, left-aligned text. - Navigation Bar (
.menu
) - Sticks to the top (top: 0
) and matches the header with a black background. - Navigation Links (
.menu a
) - Uses Arial font for clarity, with spacing, alignment, and hover effects (color: #f2f2f2 → #ff9f1c
). - Image Container (
.image-container
) - Ensures images are fully responsive (max-width: 100%
) and prevents overflowing (max-height: 100vh
). - Content (
.content
) - Adds padding and justified text for a neat layout, withfont-size: 20px
for readability.
Output:
Read Also:
- Announcement Popup Box Using Html, Css and PopboxJs
- Cursor Animation With Hover Effect Using GSAP | HTML, CSS And GSAP
- Custom Mouse Cursor Javascript | HTML, CSS And PointerJs
- Html Elements Smooth Drag And Drop Animation | HTML, CSS And Sortable
- Particle Background Animation | HTML, CSS And ParticleJs
- Responsive Portfolio Landing Page | HTML, CSS, jQuery And GSAP
- Two Image Slider | HTML, CSS And JsPlugin
Read Also:
- 12+ Best Competitive Coding Challenge Websites
- 12+ Shortcut Keys Of Visual Studio Code Editor
- 15+ Best Visual Studio Code Extensions For Web Development
- 09+ Most Popular Blogs To Learn Web Development
- 06+ Top Online Websites To Learn HTML And CSS
- 07+ Best Free Blogging Platform To Make Money
- 07+ Best Google Fonts Collection For Website
- 40+ Black And White Wallpapers Collection
- 10+ CSS Frameworks For Front-End Web Development
04. Youtube Video
To enhance your understanding of this topic, we have included a YouTube video from our Rustcode channel. This tutorial provides a step-by-step guide on creating a sticky navigation bar using pure CSS.
If you're passionate about web development and UI design, we invite you to explore more videos on our YouTube channel. We regularly share high-quality tutorials to help you refine your frontend skills and stay updated with the latest trends.
After going through this article and watching the YouTube video, you can download the complete source code and experiment with different styles, layouts, and features to tailor it to your project needs. This will help reinforce your understanding and allow you to create a fully customized sticky navigation bar for your website.
Read Also:
- How To Generate Random Rgb Color Using Javascript
- How To Generate a Random Color in JavaScript
- How To Sort Alphabetically Html Unordered Elements Using JavaScript
- How to Append Text to a DIV using JavaScript
- How to Call a JavaScript Function on Page Load
- How to Get Random Value from Array in Javascript
- How to Get an Object Keys and Values in JavaScript
- How to add two numbers in javascript
- How to apply foreach loop on an array in javascript
- How to check a string contains numeric digits using javascript
- How to check data type in javascript
- How to check whether a string contains a substring in JavaScript
- How to clear javascript console in Google Chrome
- How to convert each character in the string to an array using javascript
- How to convert radians to degrees using javascript
Comments
Post a Comment