Tailwindcss 下拉项目飞到屏幕边缘而不是在下拉按钮下方

Tailwindcss Dropdown item flying off to edge of the screen instead of under the dropdown button

所以我正在使用 Rails、Vue 和 TailwindCss 1.0+

制作应用程序

目前我正在尝试为我的产品制作一个下拉菜单,但是当我点击下拉按钮时,包含我的项目的下拉菜单飞到了屏幕的边缘,而它应该在我的按钮下面..

我不太确定哪里出错了。

问题图片:

下拉菜单如下所示:

<!-- Start LG Products Dropdown -->
  <div class="hidden lg:inline-block">
    <button @click="prodOpen = !prodOpen" role="button" class="relative z-10 inline-block select-none focus:outline-none text-base font-normal text-blue-600 hover:text-green-600 header-font focus:text-green-600">
      <i class="fal fa-sitemap"></i><span class="ml-1">Products</span>
    </button>
    <button v-if="prodOpen" @click="prodOpen = false" class="fixed inset-0 bg-black opacity-25 h-full w-full cursor-default"></button>
  </div>
  <div v-if="prodOpen" class="absolute left-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
    <slot name="dropdown-items"></slot>
  </div>
<!-- End LG Products Dropdown -->

这是整个导航组件的代码:

<template>
  <nav class="flex items-center justify-between flex-wrap bg-white p-6 w-full fixed">
    <a href="https://loadze.com">
      <h1>
        <div class="flex items-center flex-shrink-0 text-blue-600 mr-6 logoFont">
          <span class="font-bold text-3xl tracking-tight"><i class="far fa-truck-loading text-2xl"></i>LOADZE</span>
        </div>
      </h1>
    </a>

    <div class="block lg:hidden">
      <button @click="navOpen = !navOpen" class="flex items-center px-3 py-2 border rounded text-blue-600 border-blue-600 hover:text-green-600 hover:border-green-600 focus:outline-none">
        <svg v-if="!navOpen" aria-hidden="true" focusable="false" data-prefix="far" data-icon="bars" class="svg-inline--fa fa-bars fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg>
        <svg v-if="navOpen" aria-hidden="true" focusable="false" data-prefix="far" data-icon="times" class="svg-inline--fa fa-times fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path fill="currentColor" d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"></path></svg>
      </button>
    </div>

    <div :class="navOpen ? 'block' : 'hidden'" class="w-full block flex-grow lg:flex lg:items-center lg:w-auto">
      <div class="text-sm lg:flex-grow">
        <slot name="nav-left"></slot>

        <!-- Start LG Products Dropdown -->
          <div class="hidden lg:inline-block">
            <button @click="prodOpen = !prodOpen" role="button" class="relative z-10 inline-block select-none focus:outline-none text-base font-normal text-blue-600 hover:text-green-600 header-font focus:text-green-600">
              <i class="fal fa-sitemap"></i><span class="ml-1">Products</span>
            </button>
            <button v-if="prodOpen" @click="prodOpen = false" class="fixed inset-0 bg-black opacity-25 h-full w-full cursor-default"></button>
          </div>
          <div v-if="prodOpen" class="absolute left-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
            <slot name="dropdown-items"></slot>
          </div>
        <!-- End LG Products Dropdown -->
      </div>
      <div>
        <slot name="nav-right"></slot>
      </div>
    </div>
  </nav>
</template>

<script>
export default {
  data () {
    return {
      navOpen: false,
      prodOpen: false
    }
  }
}
</script>

我没有完全理解你的问题。但是,如果我看到屏幕截图,我想这就是您所说的对齐方式。基于这个结论。

如果是这种情况,您必须更改以下内容:left-0right-0

<div v-if="prodOpen" class="absolute left-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
    <slot name="dropdown-items"></slot>
</div>

收件人:

<div v-if="prodOpen" class="absolute right-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
    <slot name="dropdown-items"></slot>
</div>

这将使 div 从右到左对齐,如果 extends/needs 更多空间,它将扩展到屏幕中间。