
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How to create a responsive navigation bar with dropdown in CSS?
Following is the code to create a responsive navigation bar with dropdown −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> *,*::after,*::before{ box-sizing: border-box; } .menu-btn { font-size: 18px; font-weight: bold; display: inline-block; text-align: center; background-color: #040008; color: white; padding: 20px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; border: none; width: 100%; } .dropdown-menu { position: relative; display: inline-block; } .menu-content { display: none; position: absolute; width: 100%; background-color: #017575; min-width: 160px; z-index: 1; } nav{ background-color: #017575; width: 100%; } .links,.links-hidden{ display: inline-block; color: rgb(255, 255, 255); text-decoration: none; font-size: 18px; font-weight: bold; padding: 20px; } .links-hidden:hover,.links:hover { background-color: rgb(8, 107, 46); } .dropdown-menu:hover .menu-content { display: block; } .dropdown-menu:hover .menu-btn { background-color: #3e8e41; } .hamburger { color: white; font-weight: bolder; display: none; } @media screen and (max-width: 880px) { nav a:not(:first-child) { display: none; } nav a.hamburger { float: right; display: block; padding: 12px; } .dropdown-menu{ display: none; } nav.openNav a.hamburger { position: relative; } nav.openNav a { float: none; display: block; text-align: center; } } nav.openNav div.dropdown-menu{ display: block; width: 100%; } </style> </head> <body> <nav> <a class="links" href="#">HOME</a> <a class="links" href="#">EMPLOYEES</a> <a class="links" href="#">CAREER</a> <a class="links" href="#">Our History</a> <a class="links" href="#">Fund Us</a> <a class="links" href="#">More Info</a> <div class="dropdown-menu"> <button class="menu-btn">Open <</button> <div class="menu-content"> <a class="links-hidden" href="#">Contact Us</a> <a class="links-hidden" href="#">Visit Us</a> <a class="links-hidden" href="#">About Us</a> </div> </div> <a class="hamburger">☰</a> </nav> <script> var x = document.getElementsByTagName("nav")[0]; function toggleNav() { if (x.className === "") { x.className = " openNav"; } else { x.className = ""; } } document.querySelector(".hamburger").addEventListener("click", toggleNav); </script> </body> </html>
Output
The above code will produce the following output −
On resizing the window to 880px or less −
On opening the hamburger menu and then the dropdown −
- Related Articles
- How to create a dropdown navigation bar with CSS?
- How to create a responsive side navigation menu with CSS?
- How to create a mega menu (full-width dropdown menu in a navigation bar) with HTML and CSS?
- How to create a navigation bar with equal-width navigation links with CSS?
- Create a Horizontal Navigation Bar with CSS
- Create a responsive navigation menu with CSS Media Queries
- How to create a responsive navigation menu with icons, using CSS?\n
- How to create a responsive bottom navigation menu with CSS and JavaScript?
- How to create a navigation bar with a centred link/logo with CSS?
- How to Create an On Scroll Fixed Navigation Bar with CSS?
- How to create a navigation bar with left-aligned and right-aligned links with CSS?
- How to create a responsive navigation menu with a login form inside of it with HTML and CSS?
- How to add link dividers in a Navigation Bar with CSS
- Build a Vertical Navigation Bar with CSS
- Center links in a Navigation Bar with CSS

Advertisements