Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mathewp's avatar

Tailwind Alpine js drop down is opening on page reload

Hi all, I am using tailwind and alpine to open/close a drop down menu. It is working fine. But it will open and close when a page reload. Some solutions found to set the display:none in style. but it is not working. Any solutions for this please....

0 likes
7 replies
mathewp's avatar

\div x-data="{ dropdownOpen: false }" class=" relative "> <button @click="dropdownOpen = ! dropdownOpen" class="relative block h-8 w-8 rounded-full overflow-hidden shadow focus:outline-none ">

mathewp's avatar

< ul x-show="dropdownOpen" @click.away="dropdownOpen=false" class=" relative fixed inset-0 h-full w-full z-10">

                <li  class="  absolute right-0 mt-2 w-48 bg-white rounded-md overflow-hidden shadow-xl z-10">
                    <a href="#" class=" block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-600 hover:text-white">Profile</a>
                    <a href="#" class=" block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-600 hover:text-white">Products</a>
                    <a href="/login" class=" block px-4 py-2 text-sm text-gray-700 hover:bg-indigo-600 hover:text-white">Logout</a>
                </li>
        </ul>
    </div>
Snapey's avatar
Snapey
Best Answer
Level 122

you mean it briefly appears? use x-cloak

4 likes
mathewp's avatar

yes. I have tried x-cloak .. in a template tag.. but it is hiding the button. please tell me what is the correct method to use x-cloak

mathewp's avatar

yes i used x-cloak in div tag and used [x-cloak] { display: none } in css.

It is working fine now....

thanks to all

Please or to participate in this conversation.