首页 > 解决方案 > Tailwind 响应式 flexbox 属性未按预期工作

问题描述

默认情况下,ul 有一个justify-start flexbox 属性。当为屏幕应用响应式设计时:它将是justify-center,对于屏幕: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>

标签: htmlcssflexboxfrontendtailwind-css

解决方案


您添加了通用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'>

推荐阅读