EkoAI

About EkoAI

EkoAI pioneers AI-driven solutions, empowering businesses with intelligent automation and innovation.

Account

Follow Us

Create a responsive navigation bar with dropdown menus.
user

Here’s a simple navigation bar with a dropdown menu using HTML, CSS, and JavaScript.

Code Example
HTML
                                            
                                                <!DOCTYPE html>
                                                <html lang="en">
                                                <head>
                                                <meta charset="UTF-8">
                                                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                                                <title>Responsive Navbar</title>
                                                <link rel="stylesheet" href="styles.css">
                                                </head>
                                                <body>
                                                <nav class="navbar">
                                                    <ul>
                                                        <li><a href="#">Home</a></li>
                                                        <li><a href="#">Services</a>
                                                            <ul class="dropdown">
                                                                <li><a href="#">Web Design</a></li>
                                                                <li><a href="#">App Development</a></li>
                                                            </ul>
                                                        </li>
                                                        <li><a href="#">About</a></li>
                                                        <li><a href="#">Contact</a></li>
                                                    </ul>
                                                </nav>
                                                </body>
                                                </html>
                                            
                                        
CSS (styles.css)
                                            
                                                body {
                                                    font-family: Arial, sans-serif;
                                                    margin: 0;
                                                    padding: 0;
                                                    background-color: #f4f4f4;
                                                }
                                                .navbar {
                                                    background-color: #333;
                                                    overflow: hidden;
                                                }
                                                .navbar ul {
                                                    list-style: none;
                                                    margin: 0;
                                                    padding: 0;
                                                    display: flex;
                                                }
                                                .navbar li {
                                                    position: relative;
                                                }
                                                .navbar a {
                                                    color: white;
                                                    padding: 14px 20px;
                                                    display: block;
                                                    text-decoration: none;
                                                }
                                                .navbar a:hover {
                                                    background-color: #575757;
                                                }
                                                .dropdown {
                                                    display: none;
                                                    position: absolute;
                                                    background-color: #333;
                                                    top: 100%;
                                                    left: 0;
                                                }
                                                .navbar li:hover .dropdown {
                                                    display: block;
                                                }
                                            
                                        
JavaScript (script.js)
                                            
                                                const dropdowns = document.querySelectorAll('.navbar li');
                                                dropdowns.forEach(dropdown => {
                                                    dropdown.addEventListener('mouseover', () => {
                                                        dropdown.querySelector('.dropdown').style.display = 'block';
                                                    });
                                                    dropdown.addEventListener('mouseout', () => {
                                                        dropdown.querySelector('.dropdown').style.display = 'none';
                                                    });
                                                });
                                            
                                        
Features:
  • CSS Styling: The navbar has a sleek design with hover effects and dropdown menus.
  • JavaScript Functionality: The dropdown appears when hovering over the menu items.
  • Responsive: Adjusts well across various screen sizes.

Customize the navbar to fit your website’s needs.

Attach files