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 badges1 Answer
Reset to default 1Two 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
评论列表(0条)