最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Adding custom variants to TailwindCSS 4 - Stack Overflow

programmeradmin7浏览0评论

So the time has come to update my boilerplate to Tailwind 4, and I can't work out how to transfer my custom variant setup. In my Tailwind 3 tailwind.config.js I have this:

plugins: [
    plugin(function({ addVariant }) {
      addVariant('js', '.js &')
      addVariant('no-js', '.no-js &')
    })
  ],

To add a couple of variants. I think I need to use the new @custom-variant in my styles.css file but I can't work out the syntax. Or I may be barking up the wrong tree. All my other settings I have managed to move over fine.

So the time has come to update my boilerplate to Tailwind 4, and I can't work out how to transfer my custom variant setup. In my Tailwind 3 tailwind.config.js I have this:

plugins: [
    plugin(function({ addVariant }) {
      addVariant('js', '.js &')
      addVariant('no-js', '.no-js &')
    })
  ],

To add a couple of variants. I think I need to use the new @custom-variant in my styles.css file but I can't work out the syntax. Or I may be barking up the wrong tree. All my other settings I have managed to move over fine.

Share Improve this question asked Mar 20 at 20:50 Mike HarrisonMike Harrison 7882 gold badges16 silver badges45 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The equivalent for those custom variants would be:

@custom-variant js (.js &);
@custom-variant no-js (.no-js &);

The first token is the name of the variant. The second parameter is the selector modifier.

发布评论

评论列表(0)

  1. 暂无评论