跳到正文
Skillpedia
网站与界面(前端)29k · #9366

tailwind-v4

它能做什么

这项技能是一份指南,帮助正确编写 Tailwind CSS 第 4 版代码。它指出了新代码中不应再出现的旧版第 3 版写法。

适用场景

  • ✓当你在项目中编写或修改 Tailwind 样式时。
  • ✓当你想把旧的 Tailwind 第 3 版代码迁移到第 4 版时。
  • ✓当你想用新的配置方式设置自定义主题颜色时。

技能链接

https://github.com/mastra-ai/mastra/blob/main/.claude/skills/tailwind-v4/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/mastra-ai/mastra/blob/main/.claude/skills/tailwind-v4/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请把这个组件中的样式更新为 Tailwind 第 4 版语法,并移除旧的第 3 版写法。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会使用 Tailwind 第 4 版基于 CSS 的配置方式,而不是 JavaScript 配置文件,并在使用某个工具类之前检查该项目所用版本中是否存在它。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Tailwind CSS v4

How to write idiomatic Tailwind v4 and spot v3-era syntax that still compiles but should not appear in new code.

Version and sources

Check the pinned version before using recent utilities: the playground packages pin tailwindcss in their package.json (4.3.3 at the time of writing, including v4.3 utilities like scrollbar-*, zoom-*, and tab-*). When unsure whether a utility, variant, or directive exists in the pinned version, verify against the docs instead of guessing:

CSS-first configuration

Tailwind v4 is configured in CSS, not JavaScript.

Use Never use (v3-era)
@import 'tailwindcss' @tailwind base/components/utilities
@theme { --color-x: ...; } for tokens that should generate utilities tailwind.config.ts for new work
@utility name { ... } for custom utilities (works with variants) @layer utilities { .name { ... } }
@custom-variant dark (&:is(.dark *)) JS plugins / addVariant
@source "path" / @source inline("...") for extra sources / safelisting content array / safelist config
@variant dark { ... } to apply a Tailwind variant inside custom CSS duplicating media queries / selectors
@reference "app.css" for @apply in scoped styles (Vue, CSS Modules) duplicating stylesheet imports
var(--color-x) in CSS, getComputedStyle in JS theme() function, resolveConfig
@config "…" / @plugin "…" only for existing JS-config integrations adding new JS configs or plugins

@theme variables are API: each one emits a native CSS variable AND generates utilities (--color-* → bg-*/text-*/border-*/..., --text-* → text-*, --shadow-* → shadow-*, --animate-* → animate-*, --breakpoint-* → responsive variants). A plain :root { --x: ...; } variable generates nothing — use it for runtime-only values. When a token's value references another variable (--color-x: var(--y)), declare it in @theme inline so the utility resolves the reference at the declaration site. In custom CSS, --alpha(var(--color-x) / 50%) and --spacing(4) replace v3 theme() math.

v3 → v4 renames

Bare names shifted one step down the scale, so the v3 spelling silently renders smaller or lighter:

v3 v4
shadow-sm / shadow shadow-xs / shadow-sm
drop-shadow-sm / drop-shadow drop-shadow-xs / drop-shadow-sm
blur-sm / blur blur-xs / blur-sm
rounded-sm / rounded rounded-xs / rounded-sm
outline-none outline-hidden (a11y-safe); outline-none now truly removes it
ring (3px) ring-3; the default ring is now 1px currentColor
bg-opacity-50, text-opacity-* opacity modifier: bg-black/50, text-white/50
bg-gradient-to-r bg-linear-to-r (plus new bg-conic-*, bg-radial-*)
!bg-red-500 (prefix) bg-red-500! (suffix)
flex-shrink-* / flex-grow-* shrink-* / grow-*
bg-[--var] bg-(--var); brackets now require bg-[var(--var)]
grid-cols-[a,b] (commas) underscores: grid-cols-[max-content_auto]

Prefer generated utilities over arbitrary values

The spacing scale is infinite — every number compiles via calc(var(--spacing) * n) — so mo

常见问题

项目仍然需要 tailwind 配置文件吗?

对于新的工作,配置写在 CSS 中,而不是 JavaScript 配置文件中。

它如何知道哪些功能可用?

它会检查项目锁定的 Tailwind 版本,并在不确定时查阅官方文档。

旧语法会出错吗?

很多旧语法仍然可以编译,但这项技能会引导新代码避免使用它们。

详情

作者的原始描述

Tailwind CSS v4 usage guide and v3-to-v4 differences. This skill should be used when writing, reviewing, or refactoring any Tailwind CSS code in this repo. Triggers on tasks involving Tailwind classes, @theme blocks, CSS-first configuration, or cleanup of v3-era syntax.

repo: mastra-ai/mastra

热度

GitHub 星标
29k
排名
#9366
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能