Tailwind dropdown not working
March 30, 2025 · AI Conversations
Dashboard
Settings
Earnings
Separated link
above tailwind dropdown not wokring
—
### ✅ Check These Steps to Fix It:
#### 1. **Make sure Flowbite is installed**
You need to have Flowbite installed and configured properly.
Install via npm/yarn:
npm install flowbite
# or
yarn add flowbite
—
#### 2. **Import Flowbite JS**
Add this to your main JS file (e.g., `app.js` or `main.js`):
import 'flowbite';
Or, if you're using a CDN (for testing or simple setup), add this just before your closing “ tag:
<script src="https://unpkg.com/flowbite@latest/dist/flowbite.min.js"></script>
—
#### 3. **Tailwind Config Update**
Make sure your `tailwind.config.js` includes Flowbite:
module.exports = {
content: [
"./node_modules/flowbite/**/*.js",
"./path-to-your-files/**/*.html", // update this as per your project structure
],
theme: {
extend: {},
},
plugins: [
require('flowbite/plugin')
],
}
—
#### 4. **Build Your Tailwind CSS Again**
After changing `tailwind.config.js`, recompile:
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
# or however your build is set up
—
### ✅ Final HTML (for CDN users)
Here's a working example using Flowbite CDN:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropdown Example</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/flowbite@latest/dist/flowbite.min.js"></script>
</head>
<body>
<button id="dropdownDividerButton" data-dropdown-toggle="dropdownDivider" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">
Dropdown divider
<svg class="w-2.5 h-2.5 ms-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4"/>
</svg>
</button>
<div id="dropdownDivider" class="z-10 hidden bg-white divide-y divide-gray-100 rounded-lg shadow-sm w-44 dark:bg-gray-700 dark:divide-gray-600">
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownDividerButton">
<li>
<a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Dashboard</a>
</li>
<li>
<a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Settings</a>
</li>
<li>
<a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Earnings</a>
</li>
</ul>
<div class="py-2">
<a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">Separated link</a>
</div>
</div>
</body>
</html>
—
If you're still stuck, let me know:
– Are you using a build tool like Vite, Laravel Mix, etc.?
– Are you using the Flowbite CDN or installed it via npm/yarn?
I'll tailor the solution accordingly.
Here’s a minimal working version of your dropdown using **only Tailwind CSS** + **basic JS**:
—
### ✅ Working Dropdown (No Flowbite)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Dropdown</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="p-10">
<button id="dropdownToggle" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center">
Dropdown divider
<svg class="w-2.5 h-2.5 ms-3 ml-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4"/>
</svg>
</button>
<div id="dropdownMenu" class="mt-2 hidden bg-white divide-y divide-gray-100 rounded-lg shadow-sm w-44 dark:bg-gray-700 dark:divide-gray-600">
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200">
<li><a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Dashboard</a></li>
<li><a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Settings</a></li>
<li><a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Earnings</a></li>
</ul>
<div class="py-2">
<a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">Separated link</a>
</div>
</div>
<script>
const toggleBtn = document.getElementById('dropdownToggle');
const dropdown = document.getElementById('dropdownMenu');
toggleBtn.addEventListener('click', () => {
dropdown.classList.toggle('hidden');
});
// Optional: Click outside to close
document.addEventListener('click', (event) => {
if (!toggleBtn.contains(event.target) && !dropdown.contains(event.target)) {
dropdown.classList.add('hidden');
}
});
</script>
</body>
</html>
—
### ✅ What’s Going On Here:
– **Tailwind handles all styling**
– `hidden` class is toggled to show/hide the dropdown
– Optional enhancement: click outside to close
—
Let me know if you want:
– Animation for the dropdown
– Support for keyboard accessibility
– Multiple dropdowns on one page
I can enhance it further if needed!