- 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
Center links in a Navigation Bar with CSS
To center links in a navigation bar, you need to add ‘text-align: center’ to <li>
Example
<!DOCTYPE html> <html> <head> <style> ul { list-style-type: none; margin: 0; padding: 0; width: 200px; } li a { display: block; background-color: #F0E7E7; } .active { background-color: #4CAF50; color: white; } li { text-align: center; border-bottom: 1px solid #555; } </style> </head> <body> <ul> <li><a href = "#home">Home</a></li> <li><a href = "#company" class = "active">Company</a></li> <li><a href = "#product">Product</a></li> <li><a href = "#services">Services</a></li> <li><a href = "#contact">Contact</a></li> </ul> </body> </html>
- Related Articles
- How to create a navigation bar with equal-width navigation links with CSS?
- How to create a navigation bar with left-aligned and right-aligned 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?
- How to create bottom bordered (underline) navigation links with CSS?
- Set style to current link in a Navigation Bar with CSS
- How to add link dividers in a Navigation Bar with CSS
- How to create a responsive navigation bar with dropdown in CSS?
- Build Horizontal Navigation Bar with Floating List Items in CSS
- Build Horizontal Navigation Bar with Inline List Items in CSS
- How to create a navigation bar with a centred link/logo with CSS?
- How to resize a navigation bar on scroll with CSS and JavaScript?
- How to Create an On Scroll Fixed Navigation Bar with CSS?
- How to slide down a navigation bar on scroll with CSS and JavaScript?

Advertisements