Here's a pure HTML and CSS responsive top menu with all the features you requested:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Top Menu - No JS</title>
<style>
:root {
--primary-color: #3498db;
--secondary-color: #2980b9;
--text-color: #333;
--bg-color: #f8f9fa;
--menu-bg: #fff;
--border-color: #ddd;
--hover-color: #e9f5ff;
--active-color: #d4ebff;
--shadow: 0 2px 5px rgba(0,0,0,0.1);
--border-radius: 8px;
--transition: all 0.3s ease;
}
[data-theme="dark"] {
--primary-color: #4dabf7;
--secondary-color: #339af0;
--text-color: #f8f9fa;
--bg-color: #212529;
--menu-bg: #343a40;
--border-color: #495057;
--hover-color: #343a40;
--active-color: #495057;
--shadow: 0 2px 5px rgba(0,0,0,0.3);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
transition: var(--transition);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
.header {
background-color: var(--menu-bg);
box-shadow: var(--shadow);
position: relative;
transition: var(--transition);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 15px;
}
.nav-container {
display: flex;
align-items: center;
justify-content: space-between;
height: 70px;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
color: var(--primary-color);
text-decoration: none;
display: flex;
align-items: center;
gap: 8px;
}
.logo svg {
width: 24px;
height: 24px;
fill: currentColor;
}
/* Theme toggle */
.theme-toggle {
position: relative;
width: 60px;
height: 30px;
margin-left: 15px;
}
.theme-toggle input {
opacity: 0;
width: 0;
height: 0;
}
.theme-toggle-label {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--border-color);
transition: var(--transition);
border-radius: 30px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 5px;
}
.theme-toggle-label:before {
content: "";
position: absolute;
height: 22px;
width: 22px;
left: 4px;
bottom: 4px;
background-color: white;
transition: var(--transition);
border-radius: 50%;
z-index: 2;
}
.theme-toggle-label .sun,
.theme-toggle-label .moon {
width: 16px;
height: 16px;
fill: var(--text-color);
z-index: 1;
}
.theme-toggle input:checked + .theme-toggle-label {
background-color: var(--primary-color);
}
.theme-toggle input:checked + .theme-toggle-label:before {
transform: translateX(30px);
}
/* Main navigation */
.nav-menu {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
.nav-item {
position: relative;
}
.nav-link {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 15px;
color: var(--text-color);
text-decoration: none;
border-radius: var(--border-radius);
transition: var(--transition);
}
.nav-link:hover,
.nav-link:focus {
background-color: var(--hover-color);
}
.nav-link.active {
background-color: var(--active-color);
color: var(--primary-color);
}
.nav-link svg {
width: 18px;
height: 18px;
fill: currentColor;
}
/* Dropdown menus */
.dropdown-toggle {
position: relative;
padding-right: 25px;
}
.dropdown-toggle::after {
content: "";
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
border-width: 5px;
border-style: solid;
border-color: var(--text-color) transparent transparent transparent;
transition: var(--transition);
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
min-width: 200px;
background-color: var(--menu-bg);
border-radius: var(--border-radius);
box-shadow: var(--shadow);
list-style: none;
padding: 8px 0;
margin: 0;
opacity: 0;
visibility: hidden;
transform: translateY(10px);
transition: var(--transition);
z-index: 100;
}
.dropdown-item {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 15px;
color: var(--text-color);
text-decoration: none;
transition: var(--transition);
}
.dropdown-item:hover,
.dropdown-item:focus {
background-color: var(--hover-color);
}
.dropdown-item svg {
width: 16px;
height: 16px;
fill: currentColor;
}
/* Show dropdown on hover and focus */
.nav-item:hover > .dropdown-menu,
.nav-item:focus-within > .dropdown-menu {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.nav-item:hover > .nav-link.dropdown-toggle::after,
.nav-item:focus-within > .nav-link.dropdown-toggle::after {
transform: translateY(-50%) rotate(180deg);
}
/* Nested dropdowns */
.dropdown-submenu {
position: relative;
}
.dropdown-submenu > .dropdown-item {
position: relative;
padding-right: 25px;
}
.dropdown-submenu > .dropdown-item::after {
content: "";
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
border-width: 5px;
border-style: solid;
border-color: transparent transparent transparent var(--text-color);
transition: var(--transition);
}
.dropdown-submenu > .dropdown-menu {
top: 0;
left: 100%;
margin-left: 0;
}
.dropdown-submenu:hover > .dropdown-item::after,
.dropdown-submenu:focus-within > .dropdown-item::after {
transform: translateY(-50%) rotate(90deg);
}
/* Search form */
.search-container {
position: relative;
margin-left: 15px;
}
.search-toggle {
background: none;
border: none;
color: var(--text-color);
cursor: pointer;
padding: 10px;
border-radius: var(--border-radius);
transition: var(--transition);
}
.search-toggle:hover,
.search-toggle:focus {
background-color: var(--hover-color);
}
.search-toggle svg {
width: 20px;
height: 20px;
fill: currentColor;
}
.search-form {
position: absolute;
right: 0;
top: 100%;
width: 0;
overflow: hidden;
transition: var(--transition);
opacity: 0;
visibility: hidden;
display: flex;
background-color: var(--menu-bg);
border-radius: var(--border-radius);
box-shadow: var(--shadow);
z-index: 100;
}
.search-container:hover .search-form,
.search-container:focus-within .search-form,
.search-form:focus-within {
width: 250px;
opacity: 1;
visibility: visible;
}
.search-input {
flex: 1;
padding: 10px 15px;
border: none;
background: transparent;
color: var(--text-color);
outline: none;
}
.search-submit {
background: var(--primary-color);
color: white;
border: none;
padding: 10px 15px;
cursor: pointer;
border-radius: 0 var(--border-radius) var(--border-radius) 0;
transition: var(--transition);
}
.search-submit:hover,
.search-submit:focus {
background: var(--secondary-color);
}
/* Mobile menu toggle */
.menu-toggle {
display: none;
background: none;
border: none;
color: var(--text-color);
cursor: pointer;
padding: 10px;
border-radius: var(--border-radius);
transition: var(--transition);
}
.menu-toggle:hover,
.menu-toggle:focus {
background-color: var(--hover-color);
}
.menu-toggle svg {
width: 24px;
height: 24px;
fill: currentColor;
}
/* Tablet styles */
@media (max-width: 992px) {
.nav-link {
flex-direction: column;
text-align: center;
padding: 15px;
}
.nav-link svg {
margin-bottom: 5px;
}
}
/* Mobile styles */
@media (max-width: 768px) {
.menu-toggle {
display: block;
}
.nav-container {
flex-wrap: wrap;
}
.nav-menu-container {
position: fixed;
top: 70px;
left: -100%;
width: 80%;
height: calc(100vh - 70px);
background-color: var(--menu-bg);
transition: var(--transition);
overflow-y: auto;
z-index: 1000;
box-shadow: var(--shadow);
}
#mobile-menu-toggle:checked ~ .nav-menu-container {
left: 0;
}
.nav-menu {
flex-direction: column;
width: 100%;
}
.nav-item {
width: 100%;
}
.nav-link {
padding: 15px;
border-radius: 0;
justify-content: flex-start;
}
.dropdown-toggle::after {
right: 15px;
}
.dropdown-menu {
position: static;
opacity: 1;
visibility: visible;
transform: none;
box-shadow: none;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
width: 100%;
padding: 0;
}
.nav-item:hover > .dropdown-menu,
.nav-item:focus-within > .dropdown-menu {
max-height: 500px;
}
.dropdown-item {
padding-left: 30px;
}
.dropdown-submenu > .dropdown-menu .dropdown-item {
padding-left: 45px;
}
.dropdown-submenu > .dropdown-item::after {
border-color: var(--text-color) transparent transparent transparent;
right: 15px;
}
.dropdown-submenu:hover > .dropdown-item::after,
.dropdown-submenu:focus-within > .dropdown-item::after {
transform: translateY(-50%) rotate(180deg);
}
.dropdown-submenu > .dropdown-menu {
left: 0;
}
/* Keep search visible in mobile */
.search-container {
order: -1;
margin-right: auto;
margin-left: 15px;
}
.search-form {
position: fixed;
top: 15px;
right: 70px;
width: 0;
}
.search-container:hover .search-form,
.search-container:focus-within .search-form,
.search-form:focus-within {
width: calc(100% - 160px);
}
}
/* Tab menu style when collapsed */
.menu-tab {
position: fixed;
top: 50%;
left: 0;
transform: translateY(-50%);
background-color: var(--primary-color);
color: white;
padding: 15px;
border-radius: 0 var(--border-radius) var(--border-radius) 0;
cursor: pointer;
z-index: 999;
display: none;
}
.menu-tab svg {
width: 24px;
height: 24px;
fill: currentColor;
}
.search-tab {
position: fixed;
top: calc(50% + 60px);
left: 0;
transform: translateY(-50%);
background-color: var(--primary-color);
color: white;
padding: 15px;
border-radius: 0 var(--border-radius) var(--border-radius) 0;
cursor: pointer;
z-index: 999;
display: none;
}
.search-tab svg {
width: 24px;
height: 24px;
fill: currentColor;
}
#tab-menu-toggle:checked ~ .header {
transform: translateX(0);
}
#tab-search-toggle:checked ~ .search-form-tab {
transform: translateX(0);
}
.search-form-tab {
position: fixed;
top: calc