【问题标题】:How to use tailwindcss colors in custom css classes?如何在自定义 CSS 类中使用 tailwindcss 颜色?
【发布时间】:2021-08-16 16:02:54
【问题描述】:

我可以使用预定义的tailwind 类在 HTML 中设置颜色,例如:

<div class="border border-purple-500"></div>

但我也想在我的自定义 css 中使用相同的颜色,例如:

.my-class {
    border: 1px solid $purple-500;
}

是否可以在 CSS 中获取顺风颜色值?

【问题讨论】:

    标签: tailwind-css


    【解决方案1】:

    是的。你可以使用theme()directive

    .my-class {
        border: 1px solid theme('colors.purple.500');
    }
    

    或通过@apply

    .my-class {
        @apply border border-purple-500;
    }
    

    【讨论】:

    • 太棒了,谢谢!我知道@apply,但它不适用于:before 或:after 之类的伪类。这就是为什么我需要直接访问值。
    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 2021-09-10
    • 2019-10-24
    • 2021-11-23
    • 1970-01-01
    • 2021-01-05
    相关资源
    最近更新 更多