Tailwind CSS:在白名单中为响应式类名添加模式?

huangapple go评论56阅读模式
英文:

Tailwind CSS: add pattern for responsive classnames to safelist?

问题

在项目的Tailwind配置的白名单中,我正在使用这个模式来包括所有的填充工具:

{ 模式: /^p(\w?)-/ }

是否可以通过模式来包含响应式工具变体(例如 sm:p-, md:p-, lg:p-, ...)?

我尝试了以下方式,但Tailwind告诉我这不是一个被识别的模式:

{ 模式: /^sm:p(\w?)-/ }

英文:

I'm using this pattern in the safelist of a project's tailwind config. to include all padding utilities:

{ pattern: /^p(\w?)-/ }

Is it possible to include responsive utility variants via a pattern as well (i.e. sm:p-, md:p-, lg:p-, ...)?

I've tried the following which tailwind tells me is not a recognized pattern:

{ pattern: /^sm:p(\w?)-/ }

答案1

得分: 3

根据文档

> 模式只能匹配基础实用程序名称,例如/bg-red-.+/,如果模式包含变体修饰符,如/hover:bg-red-.+/,则不会匹配。
>
> 如果要强制 Tailwind 为任何匹配的类生成变体,请使用variants选项将它们包含在内:

因此,对于您的情况:

{
  pattern: /^p(\w?)-/,
  variants: ['sm', 'md', 'lg'],
}
英文:

As per the documentation:

> Patterns can only match against base utility names like /bg-red-.+/, and won’t match if the pattern includes a variant modifier like /hover:bg-red-.+/.
>
> If you want to force Tailwind to generate variants for any matched classes, include them using the variants option:

So for your case:

{
  pattern: /^p(\w?)-/,
  variants: ['sm', 'md', 'lg'],
}

huangapple
  • 本文由 发表于 2023年6月5日 13:21:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定