- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set the navigation bar to stay at the top of the web page with CSS
To set the navigation bar at top, use position: fixed property, with top property.
You can try to run the following code to implement a menu that stays on the top,
Example
<!DOCTYPE html> <html> <head> <style> ul { list-style-type: none; position: fixed; top: 0; width: 100%; } li { float: left; border-right: 1px solid white; } li a { display: block; padding: 8px; background-color: orange; } li:last-child { border-right: none; } div { padding:30px; margin-top:40px; background-color:white; } </style> </head> <body> <ul> <li><a href = "#home">Home</a></li> <li><a href = "#news">News</a></li> <li><a href = "#contact">Contact</a></li> <li><a href = "#about">About</a></li> </ul> <div> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> <p>Adding demo text to check fixed menu.</p> </div> </body> </html>
- Related Articles
- Set the navigation bar to stay at the bottom of the web page with CSS
- How do you get the footer to stay at the bottom of a Web page in HTML?
- Set style to current link in a Navigation Bar with CSS
- How to create a navigation bar with equal-width navigation links with CSS?
- Build a Vertical Navigation Bar with CSS
- Create a Horizontal Navigation Bar with CSS
- How to create a dropdown navigation bar with CSS?
- Center links in a Navigation Bar with CSS
- Retrofit existing web page with mobile CSS
- Set the top margin of an element with CSS
- How to add link dividers in a Navigation Bar with CSS
- How to create a responsive navigation bar with dropdown in CSS?
- How to Create an On Scroll Fixed Navigation Bar with CSS?
- Center pagination on a web page with CSS
- Build Horizontal Navigation Bar with Floating List Items in CSS

Advertisements