【问题标题】:Tailwind flex-row-reverse doesn't display spacing properlyTailwind flex-row-reverse 无法正确显示间距
【发布时间】:2021-07-25 16:10:18
【问题描述】:

我正在尝试获取两个版本的导航栏 - 一个是 LTR,另一个是 RTL。 为此,我将 flex-row-reverse 添加到两个必要的 div 中,但徽标和搜索栏之间的空间消失了。

这是没有flex-row-reverse的LTR导航栏:

<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/>
   <nav
    class="bg-gray-900 text-white px-4 py-3 flex items-center justify-between"
  >
    <div class="flex items-center space-x-4">
      <a href="#" class="text-white hover:text-gray-400">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  <path d="M12 14l9-5-9-5-9 5 9 5z" />
  <path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222" />
</svg>
      </a>
      <div class="lg:block relative">
        <input
          type="text"
          class="rounded bg-gray-700 placeholder-white w-72 px-3 py-1"
          placeholder="Search or jump to..."
        />
        <div class="absolute top-0 right-0 flex items-center h-full">
          <div
            class="
              border border-gray-600
              rounded
              text-xs text-gray-400
              px-2
              mr-2
            "
          >
            /
          </div>
        </div>
      </div>
    </div>
  </nav>

这是损坏的 RTL 版本,徽标和搜索栏之间没有间距(使用 flex-row-reverse 时):

<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/>
  <nav
    class="bg-gray-900 text-white px-4 py-3 flex flex-row-reverse items-center justify-between"
  >
    <div class="flex flex-row-reverse items-center space-x-4">
      <a href="#" class="text-white hover:text-gray-400">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  <path d="M12 14l9-5-9-5-9 5 9 5z" />
  <path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222" />
</svg>
      </a>
      <div class="lg:block relative">
        <input
          type="text"
          class="rounded bg-gray-700 placeholder-white w-72 px-3 py-1"
          placeholder="Search or jump to..."
        />
        <div class="absolute top-0 right-0 flex items-center h-full">
          <div
            class="
              border border-gray-600
              rounded
              text-xs text-gray-400
              px-2
              mr-2
            "
          >
            /
          </div>
        </div>
      </div>
    </div>
  </nav>

【问题讨论】:

    标签: html css tailwind-css


    【解决方案1】:

    根据顺风文档,reference link

    如果您的元素顺序相反(使用 flex-row-reverseflex-col-reverse),使用 space-x-reversespace-y-reverse 实用程序,以确保空间被添加到每个正确的一面 元素。

    因此,只需在您的代码中添加类 space-x-reverse,如下所示:Demo

    <div class="flex flex-row-reverse items-center space-x-4 space-x-reverse">
    

    【讨论】:

    • 谢谢 - 成功了!我需要更仔细地阅读文档
    猜你喜欢
    • 2016-11-19
    • 2013-05-11
    • 2019-08-02
    • 2021-04-09
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多