custom-variant issue in Tailwind CSS v4 with prefix - Stack Overflow

I am using Tailwind CSS v4 and have added prefix and a custom variant. Please check this example: I ex

I am using Tailwind CSS v4 and have added prefix and a custom variant. Please check this example:

I expected the active tab to have blue background with white text but it's not working as expected.

I am using Tailwind CSS v4 and have added prefix and a custom variant. Please check this example: https://play.tailwindcss/5eHxv2nUUS?file=css

I expected the active tab to have blue background with white text but it's not working as expected.

Share Improve this question asked Mar 8 at 16:47 user3631047user3631047 3,3865 gold badges24 silver badges35 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Two things:

  • Swap the variants applied to the classes so that tw: is always first.
  • Escape the colon (:) in your selector with a backslash (\). Without escaping the colon, it is parsed by the browser as the :active pseudo-class.

<script src="https://unpkg/@tailwindcss/[email protected]"></script>

<style type="text/tailwindcss">
@import "tailwindcss" prefix(tw);

@custom-variant custom-tab-active {
  &.tw\:active {
    .custom-tabs & {
      @slot;
    }
  }
}
</style>

<div class="custom-tabs tw:flex tw:border-b tw:border-gray-300">
  <button class="tw:custom-tab-active:bg-blue-500 tw:custom-tab-active:text-white tw:px-4 tw:py-2 tw:border-b-2 tw:border-transparent">
    Tab 1
  </button>
  <button class="tw:active tw:custom-tab-active:bg-blue-500 tw:custom-tab-active:text-white tw:px-4 tw:py-2 tw:border-b-2 tw:border-transparent">
    Tab 2 (Active)
  </button>
</div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744891061a4599416.html

相关推荐

  • custom-variant issue in Tailwind CSS v4 with prefix - Stack Overflow

    I am using Tailwind CSS v4 and have added prefix and a custom variant. Please check this example: I ex

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信