Dropdown按钮在使用Tailwind CSS时无法按预期工作。

huangapple go评论77阅读模式
英文:

Dropdown button won't work as expected using tailwind css

问题

当单击用户个人资料,应该显示下拉菜单,但什么都没有出现。

使用以下代码时,单击用户菜单时没有任何内容显示:

<button type="button" class="flex mr-3 text-sm bg-gray-800 rounded-full md:mr-0 focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600" id="user-menu-button" aria-expanded="false" data-dropdown-toggle="user-dropdown" data-dropdown-placement="bottom">
    <span class="sr-only">打开用户菜单</span>
    <img class="w-8 h-8 rounded-full" src="/docs/images/people/profile-picture-3.jpg" alt="用户照片">
</button>
<!-- 下拉菜单 -->
<div class="z-50 hidden my-4 text-base list-none bg-white divide-y divide-gray-100 rounded-lg shadow dark:bg-gray-700 dark:divide-gray-600" id="user-dropdown">
    <div class="px-4 py-3">
        <span class="block text-sm text-gray-900 dark:text-white">Bonnie Green</span>
        <span class="block text-sm font-medium text-gray-500 truncate dark:text-gray-400">name@flowbite.com</span>
    </div>
    <ul class="py-2" aria-labelledby="user-menu-button">
        <li>
            <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">仪表盘</a>
        </li>
        <li>
            <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">设置</a>
        </li>
        <li>
            <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">收益</a>
        </li>
        <li>
            <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">退出</a>
        </li>
    </ul>
</div>

使用此代码时,单击用户菜单时没有任何内容显示。资源链接:flowbite.com

英文:

When clicking on the user profile which is supposed to show the dropdown menu, nothing is appearing.

`     &lt;button type=&quot;button&quot; class=&quot;flex mr-3 text-sm bg-gray-800 rounded-full md:mr-0 focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600&quot; id=&quot;user-menu-button&quot; aria-expanded=&quot;false&quot; data-dropdown-toggle=&quot;user-dropdown&quot; data-dropdown-placement=&quot;bottom&quot;&gt;
        &lt;span class=&quot;sr-only&quot;&gt;Open user menu&lt;/span&gt;
        &lt;img class=&quot;w-8 h-8 rounded-full&quot; src=&quot;/docs/images/people/profile-picture-3.jpg&quot; alt=&quot;user photo&quot;&gt;
      &lt;/button&gt;
      &lt;!-- Dropdown menu --&gt;
      &lt;div class=&quot;z-50 hidden my-4 text-base list-none bg-white divide-y divide-gray-100 rounded-lg shadow dark:bg-gray-700 dark:divide-gray-600&quot; id=&quot;user-dropdown&quot;&gt;
        &lt;div class=&quot;px-4 py-3&quot;&gt;
          &lt;span class=&quot;block text-sm text-gray-900 dark:text-white&quot;&gt;Bonnie Green&lt;/span&gt;
          &lt;span class=&quot;block text-sm font-medium text-gray-500 truncate dark:text-gray-400&quot;&gt;name@flowbite.com&lt;/span&gt;
        &lt;/div&gt;
        &lt;ul class=&quot;py-2&quot; aria-labelledby=&quot;user-menu-button&quot;&gt;
          &lt;li&gt;
            &lt;a href=&quot;#&quot; class=&quot;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&quot;&gt;Dashboard&lt;/a&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;a href=&quot;#&quot; class=&quot;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&quot;&gt;Settings&lt;/a&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;a href=&quot;#&quot; class=&quot;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&quot;&gt;Earnings&lt;/a&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;a href=&quot;#&quot; class=&quot;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&quot;&gt;Sign out&lt;/a&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;`

Using this nothing is appearing when clicking on the user menu
Resouce used: flowbite.com

答案1

得分: 1

你安装了Flowbite吗?

当点击按钮时,它们很可能使用 JavaScript 来移除下拉菜单中的 hidden 类。如果只复制 HTML 和 CSS,它将无法工作。

英文:

Have you installed Flowbite?

They most likely use javascript to remove the hidden class from the dropdown menu when the button is clicked. If you just copy the HTML+CSS it won't work.

huangapple
  • 本文由 发表于 2023年2月24日 02:52:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549135.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定