覆盖链式选择器上的TailWind css@Apply指令

2022-04-24 00:00:00 css tailwind-css

有什么方法可以覆盖链接选择器上的@apply指令吗?

示例:https://play.tailwindcss.com/2nmGe5yad3

HTML

<ul>
  <li class="class-one class-two">Item 1</li>
  <li class="class-one class-two">Item 2</li>
  <li class="class-one class-two text-red-50 bg-red-800">Item 3</li>
  <li class="class-one class-two">Item 4</li>
</ul>

css

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
  /* also doesnt work with "li.class-one" selector, works only with ".class-one" selector */
  .class-one.class-two {
    @apply text-black bg-gray-100;
  }
}

解决方案

您可以将important:true设置到trawind.config中,这个page可以帮助您。请看下面的代码:

module.exports = {
  mode: 'jit',
  important: true,
  theme: {},
  variants: {},
  plugins: [],
}

相关文章