Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to create a pill navigation menu with CSS?
A pill navigation menu features rounded, button-like navigation links that resemble pills. This design provides an intuitive and modern user interface for website navigation. The pill shape is achieved using CSS border-radius property to create rounded corners.
Syntax
nav {
/* Container styles */
}
nav a {
border-radius: value;
/* Other pill styling */
}
Example: Creating a Pill Navigation Menu
The following example demonstrates how to create a complete pill navigation menu with hover effects and active states −
<!DOCTYPE html>
<html>
<head>
<style>
nav {
width: 100%;
background-color: #f8f9fa;
padding: 10px;
overflow: auto;
}
.links {
display: inline-block;
text-align: center;
padding: 12px 20px;
margin: 0 5px;
text-decoration: none;
font-size: 16px;
border-radius: 25px;
color: #333;
background-color: transparent;
transition: all 0.3s ease;
}
.links:hover {
background-color: #e9ecef;
transform: translateY(-2px);
}
.selected {
background-color: #007bff;
color: white;
}
.selected:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h2>Pill Navigation Menu</h2>
<nav>
<a class="links selected" href="#">Home</a>
<a class="links" href="#">About</a>
<a class="links" href="#">Services</a>
<a class="links" href="#">Portfolio</a>
<a class="links" href="#">Contact</a>
</nav>
</body>
</html>
A horizontal navigation menu with pill-shaped buttons appears. The "Home" button is highlighted in blue with white text. Other buttons have gray text on a light background. Hovering over buttons shows a gray background and slight upward movement effect.
Key Properties for Pill Navigation
| Property | Purpose | Typical Value |
|---|---|---|
border-radius |
Creates rounded pill shape | 20px-30px |
padding |
Adds space inside buttons | 12px 20px |
display |
Arranges links horizontally | inline-block |
transition |
Smooth hover effects | all 0.3s ease |
Conclusion
Pill navigation menus combine aesthetic appeal with functionality through rounded borders and smooth transitions. The key is using appropriate border-radius values and hover effects to create an engaging user experience.
Advertisements
