Dropdown using Tailwind Css and Tippy Js
Web2tailwind.com

Output

Code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://unpkg.com/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/tippy-bundle.umd.js"></script>
    <link href="https://unpkg.com/[email protected]^1.0/dist/tailwind.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
    <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro|Roboto&display=swap" rel="stylesheet">
</head>
<style>
    .tippy-box {
        background-color: #fff !important;
    }

    .tippy-content {
        padding: 0 !important;
    }

    .tippy-box {
        background-color: white;
    }

    .tippy-box[data-placement^='top']>.tippy-arrow::before {
        border-top-color: white;
    }

    .tippy-box[data-placement^='bottom']>.tippy-arrow::before {
        border-bottom-color: white;
    }

    .tippy-box[data-placement^='left']>.tippy-arrow::before {
        border-left-color: white;
    }

    .tippy-box[data-placement^='right']>.tippy-arrow::before {
        border-right-color: white;
    }

</style>

<body style="font-family:Roboto">
    <div class="flex justify-center items-center h-screen bg-gray-200 md:-mx-4">
        <div class="relative">
            <button data-tippy-placement="bottom-start" data-template='dropdown-content'
                class="bg-blue-600 text-gray-200 rounded-lg px-4 text-sm py-2 overflow-hidden border-gray-600 focus:outline-none focus:border-white">
                <div class="flex">
                    <span>Dropdown Buttons</span>
                    <svg class="fill-current text-gray-200" xmlns="http://www.w3.org/2000/svg" height="24"
                        viewBox="0 0 24 24" width="24">
                        <path d="M7 10l5 5 5-5z" />
                        <path d="M0 0h24v24H0z" fill="none" /></svg>
                </div>
            </button>
            <button data-tippy-placement="top-start" data-template='dropdown-content'
                class="bg-blue-600 text-gray-200 rounded-lg px-4 text-sm py-2 overflow-hidden border-gray-600 focus:outline-none focus:border-white">
                <div class="flex">
                    <span>Dropdown Buttons</span>
                    <svg class="fill-current text-gray-200" xmlns="http://www.w3.org/2000/svg" height="24"
                        viewBox="0 0 24 24" width="24">
                        <path d="M7 10l5 5 5-5z" />
                        <path d="M0 0h24v24H0z" fill="none" /></svg>
                </div>
            </button>
            <button data-tippy-placement="bottom-end" data-template='dropdown-content'
                class="bg-blue-600 text-gray-200 rounded-lg px-4 text-sm py-2 overflow-hidden border-gray-600 focus:outline-none focus:border-white">
                <div class="flex">
                    <span>Dropdown Buttons</span>
                    <svg class="fill-current text-gray-200" xmlns="http://www.w3.org/2000/svg" height="24"
                        viewBox="0 0 24 24" width="24">
                        <path d="M7 10l5 5 5-5z" />
                        <path d="M0 0h24v24H0z" fill="none" /></svg>
                </div>
            </button>
        </div>
        <div style="display: none;">
            <div id="dropdown-content">
                <div class="py-2 w-48 bg-white rounded-lg shadow-xl">
                    <a href="https://web2tailwind.com"
                        class="block px-4 py-2 text-gray-800 hover:bg-indigo-500 hover:text-white">Account
                        settings</a>
                    <a href="https://web2tailwind.com"
                        class="block px-4 py-2 text-gray-800 hover:bg-indigo-500 hover:text-white">Support</a>
                    <a href="https://web2tailwind.com"
                        class="block px-4 py-2 text-gray-800 hover:bg-indigo-500 hover:text-white">Sign out</a>
                </div>
            </div>
        </div>
    </div>
    <script>
        tippy('button', {
            content(reference) {
                const id = reference.getAttribute('data-template');
                const template = document.getElementById(id);
                return template.innerHTML;
            },
            allowHTML: true,
            theme: 'white',
            trigger: 'click',
            showOnCreate: true,
            interactive: true
        });

    </script>
</body>

</html>
© 2019 - 2021 Web2tailwind.com