【问题标题】:Tailwind responsive flexbox property is not working as expectedTailwind 响应式 flexbox 属性未按预期工作
【发布时间】:2021-04-03 20:12:47
【问题描述】:

默认情况下,ul 有一个 justify-start flexbox 属性。当为 small 屏幕应用响应式设计时:它将是 justify-center,对于 medium 屏幕:justify-around 对于屏幕:justify-evenly。 但是,对于所有屏幕尺寸,它只显示 justify-evenly 属性,它会覆盖所有其他 justify-property。 如何为不同的屏幕应用不同的 justify-property?

         <nav className='py-8'>
          <ul className='flex flex-row justify-start bg-red-400 sm:flex-row-reverse justify-center md:flex-row justify-around lg:flex-row-reverse justify-evenly'>
            <Link href='#'>
              <a className='p-2 text-2xl font-bold transition duration-500 hover:bg-indigo-300'> Beginnings</a>
            </Link>
            <Link href='#'>
              <a className='p-2 text-2xl font-bold hover:bg-indigo-300'> Now</a>
            </Link>
            <Link href='#'>
              <a className='p-2 text-2xl font-bold hover:bg-indigo-300'> Tech</a>
            </Link>
            <Link href='#'>
              <a className='p-2 text-2xl font-bold hover:bg-indigo-300'> Talks</a>
            </Link>
            <Link href='#'>
              <a className='p-2 text-2xl font-bold hover:bg-indigo-300'> Connect</a>
            </Link>
          </ul>
        </nav>

【问题讨论】:

    标签: html css flexbox frontend tailwind-css


    【解决方案1】:

    您添加了通用 justify-aroundjustify-evenly 类,而不是屏幕大小前缀 md:justify-aroundlg:justify-evenly。在 Tailwind 中,无前缀类适用于所有屏幕尺寸。前缀类适用于所有大于或等于给定前缀的屏幕尺寸。

    <ul className='flex flex-row justify-start bg-red-400 sm:flex-row-reverse justify-center md:flex-row md:justify-around lg:flex-row-reverse lg:justify-evenly'>
    

    【讨论】:

      【解决方案2】:

      您需要为每个justify-* 类添加断点前缀,否则它将应用于所有断点。因为justify-evenly 是最后一个,所以它是最终被应用的那个。

      <ul className='flex flex-row justify-start bg-red-400 sm:flex-row-reverse sm:justify-center md:flex-row md:justify-around lg:flex-row-reverse lg:justify-evenly'>
      

      【讨论】:

        猜你喜欢
        • 2022-01-17
        • 1970-01-01
        • 1970-01-01
        • 2020-04-26
        • 2021-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-27
        相关资源
        最近更新 更多