顺风位置在较小的屏幕上为绝对位置,在较大的屏幕上为右侧位置

ben*_*siu 3 css css-position tailwind-css

我有一个菜单,当屏幕较小时(比如在 SM 之前),我希望将其定位在屏幕左侧,而当屏幕较大时,将其定位在屏幕右侧。

<MenuItems
  class="
    absolute left-2 top-24 w-full mt-8
    sm:right-2 sm:top-0 sm:w-max
  "
>
Run Code Online (Sandbox Code Playgroud)

单独应用时,设置right-*可按预期工作,但以断点为前缀时sm left-*优先。

这是一种在大屏幕上取消左键的方法吗?喜欢sm:left-none

小智 6

Yesauto可用于取消定位值。所以使用sm:left-auto.

另一个(更糟糕的)选择是在较小的屏幕上使用right-full。但这样你的元素就会在屏幕外。虽然你可以像这样把它改回来:right-full translate-x-full sm:right-0 sm:translate-x-0