Dropdown-Menü-Komponente
Eine reaktionsschnelle Dropdown-Menükomponente für Finanz-/Bankschnittstellen mit Mikrointeraktionen, juwelenfarbenen Farben und Unterstützung des Dunkelmodus. Entwickelt für Benutzerbindung und Klarheit.
HTML-Code
<div class="relative inline-block text-left font-sans">
<button id="dropdown-button" type="button" class="inline-flex justify-center items-center gap-2 w-full rounded-md border border-emerald-600 bg-emerald-700 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-emerald-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-emerald-100 focus:ring-emerald-500 dark:border-emerald-500 dark:bg-emerald-600 dark:hover:bg-emerald-700 dark:text-gray-100 dark:focus:ring-offset-emerald-900 transition-all duration-300 ease-in-out transform hover:-translate-y-0.5 hover:scale-105" aria-expanded="true" aria-haspopup="true">
<svg class="-ml-1 mr-2 h-5 w-5 text-current" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.25 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.06z" clip-rule="evenodd" />
</svg>
<span>Account Options</span>
</button>
<div id="dropdown-menu" class="absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-800 transition-all duration-300 ease-out scale-95 opacity-0 invisible" role="menu" aria-orientation="vertical" aria-labelledby="dropdown-button" tabindex="-1">
<div class="py-1" role="none">
<!-- Active: "bg-gray-100 text-gray-900", Not Active: "text-gray-700" -->
<a href="#" class="text-gray-700 block px-4 py-2 text-sm hover:bg-emerald-50 hover:text-emerald-800 dark:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-emerald-400 transition-colors duration-200" role="menuitem" tabindex="-1" id="menu-item-0">
<div class="flex items-center gap-2">
<svg class="h-5 w-5 text-emerald-600 dark:text-emerald-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M10.75 4.75a.75.75 0 00-1.5 0v4.5a.75.75 0 00.75.75h4.5a.75.75 0 000-1.5h-3.75V4.75z" />
<path fill-rule="evenodd" d="M.93 2.822A.75.75 0 011.875 2.25h16.25a.75.75 0 01.945.572L19.45 4.75H.55L.93 2.822zM19.5 6.25l-.273 1.455A49.123 49.123 0 0110 16.75 49.123 49.123 0 01.773 7.705L.5 6.25h19z" clip-rule="evenodd" />
</svg>
<span>View Balance</span>
</div>
</a>
<a href="#" class="text-gray-700 block px-4 py-2 text-sm hover:bg-emerald-50 hover:text-emerald-800 dark:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-emerald-400 transition-colors duration-200" role="menuitem" tabindex="-1" id="menu-item-1">
<div class="flex items-center gap-2">
<svg class="h-5 w-5 text-emerald-600 dark:text-emerald-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M.5 9.5a.75.75 0 01.75-.75h1.612l1.64-1.612a.75.75 0 011.14-.093l1.84 2.301 3.09-3.09a.75.75 0 011.06 0l2.031 2.032c.571-1.042.868-2.146.992-3.184A.75.75 0 0118.75 4l.25 10A.75.75 0 0118.28 15.118l-1.442-.361a49.117 49.117 0 01-14.774.225l-1.444.364A.75.75 0 01.5 14.5l.25-10a.75.75 0 01.272-.5zM16.48 9.07c-1.42.062-2.812.22-4.177.472-1.393.255-2.756.55-4.089.882l-2.032-2.032 2.502-3.128c.378-.472.935-.839 1.57-.935l1.896-.284c.8-.119 1.603-.178 2.408-.178.692 0 1.38-.027 2.063-.079l2.457-1.365a.75.75 0 01.407.697v1.895l.135 1.583z" clip-rule="evenodd" />
</svg>
<span>Transfer Funds</span>
</div>
</a>
<a href="#" class="text-gray-700 block px-4 py-2 text-sm hover:bg-emerald-50 hover:text-emerald-800 dark:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-emerald-400 transition-colors duration-200" role="menuitem" tabindex="-1" id="menu-item-2">
<div class="flex items-center gap-2">
<svg class="h-5 w-5 text-emerald-600 dark:text-emerald-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M2 4.25A2.25 2.25 0 014.25 2h11.5A2.25 2.25 0 0118 4.25v2.5a.75.75 0 001.5 0v-2.5A3.75 3.75 0 0015.75 0H4.25A3.75 3.75 0 00.5 4.25v2.5a.75.75 0 001.5 0v-2.5z" clip-rule="evenodd" />
<path fill-rule="evenodd" d="M.5 10.75a.75.75 0 01.75-.75h17a.75.75 0 010 1.5h-17a.75.75 0 01-.75-.75zM1.25 13.5a.75.75 0 01.75-.75h16a.75.75 0 010 1.5H2a.75.75 0 01-.75-.75z" clip-rule="evenodd" />
<path fill-rule="evenodd" d="M7.75 16.25a.75.75 0 01.75-.75h3.5a.75.75 0 010 1.5h-3.5a.75.75 0 01-.75-.75zM2.5 7.5a.75.75 0 000 1.5h15a.75.75 0 000-1.5H2.5z" clip-rule="evenodd" />
</svg>
<span>Transaction History</span>
</div>
</a>
<a href="#" class="text-gray-700 block px-4 py-2 text-sm hover:bg-emerald-50 hover:text-emerald-800 dark:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-emerald-400 transition-colors duration-200" role="menuitem" tabindex="-1" id="menu-item-3">
<div class="flex items-center gap-2">
<svg class="h-5 w-5 text-emerald-600 dark:text-emerald-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M10.5 5h-1a.75.75 0 000 1.5h1a.75.75 0 000-1.5zM10.5 8h-1a.75.75 0 000 1.5h1a.75.75 0 000-1.5zM3 12a2 2 0 104 0 2 2 0 00-4 0z" />
<path fill-rule="evenodd" d="M2.25 5.5A2.75 2.75 0 015 2.75h10A2.75 2.75 0 0117.75 5.5v9.5a2.75 2.75 0 01-2.75 2.75H5A2.75 2.75 0 012.25 15V5.5zm3.5-.75a.75.75 0 00-1.5 0v3.5a.75.75 0 001.5 0v-4z" clip-rule="evenodd" />
<path d="M10.5 11h-1a.75.75 0 000 1.5h1a.75.75 0 000-1.5zm.75 2.25a.75.75 0 00-1.5 0v1a.75.75 0 001.5 0v-1z" />
</svg>
<span>Manage Cards</span>
</div>
</a>
</div>
</div>
</div>
<script>
const dropdownButton = document.getElementById('dropdown-button');
const dropdownMenu = document.getElementById('dropdown-menu');
function toggleDropdown() {
const isExpanded = dropdownButton.getAttribute('aria-expanded') === 'true';
if (isExpanded) {
dropdownMenu.classList.add('opacity-0', 'scale-95', 'invisible');
dropdownMenu.classList.remove('opacity-100', 'scale-100', 'visible');
dropdownButton.setAttribute('aria-expanded', 'false');
} else {
dropdownMenu.classList.remove('opacity-0', 'scale-95', 'invisible');
dropdownMenu.classList.add('opacity-100', 'scale-100', 'visible');
dropdownButton.setAttribute('aria-expanded', 'true');
}
}
dropdownButton.addEventListener('click', toggleDropdown);
// Close the dropdown if the user clicks outside of it
document.addEventListener('click', (event) => {
if (!dropdownButton.contains(event.target) && !dropdownMenu.contains(event.target)) {
const isExpanded = dropdownButton.getAttribute('aria-expanded') === 'true';
if (isExpanded) {
toggleDropdown();
}
}
});
// Close dropdown on escape key
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') {
const isExpanded = dropdownButton.getAttribute('aria-expanded') === 'true';
if (isExpanded) {
toggleDropdown();
}
}
});
</script>
Verwandte Komponenten
Dropdown-Menü Komponente 20
Eine Dropdown-Menükomponente mit einem brutalistischen Designstil unter Verwendung von Tailwind CSS, mit responsiven Effekten und Unterstützung für dunkle Themen.
Dropdown-Menü-Komponente
Eine komplexe, reaktionsschnelle Dropdown-Menükomponente, die für Dokumentations- oder Wiki-Seiten entwickelt wurde und einen klaren, minimalistischen Swiss/International Typography-Stil mit einem Ocean/Blue-Farbschema aufweist. Enthält Unterstützung für den Dunkelmodus und mehrere interaktive Elemente.
Dropdown-Menü-Komponente
Eine einfache, industriell gestaltete Dropdown-Menükomponente für Nachrichten-/Journalismus-Websites mit einer Wald-/Grün-Farbpalette und Unterstützung für den Dunkelmodus. Entwickelt, um auf allen Geräten reaktionsschnell zu sein.