
Prefer Container Queries
Skill写或评审响应式 Tailwind 代码时,让组件按所在容器的宽度而不是视口宽度调整布局:用 @container 与 @md: 等变体替换 sm:/md:/lg:,说明哪些页面级布局仍应保留视口断点,给出迁移步骤与评审时的常见错误。Tailwind v3 需要额外插件。
name: prefer-container-queries
description: "Enforce Tailwind container queries over viewport breakpoints for responsive components. Use when writing or reviewing responsive Tailwind code, when a component needs to adapt to its available space (cards, sidebars, lists, panels, anything reused in different layouts), or when migrating sm:/md:/lg: classes to @container variants."
Prefer Container Queries
Components should respond to the space they are in, not to the viewport. A card that lives in a sidebar has maybe 300px of width even on a huge screen, and a viewport breakpoint like md:flex-row will get that wrong every time. Container queries fix this: the component asks "how wide am I?" instead of "how wide is the window?".
When writing responsive Tailwind, default to container queries. Viewport breakpoints are the exception, not the rule.
How it works
Mark the parent as a container, then use @-prefixed variants on its children:
<div class="@container">
<div class="flex flex-col @md:flex-row @md:gap-6">
<img class="w-full @md:w-48" />
<div class="@md:flex-1">...</div>
</div>
</div>
@md: here means "when the container is at least 28rem wide", regardless of viewport size. This card works in a sidebar, a modal, and a full-width grid without changing a single class.
Two rules that trip people up:
- The
@containerclass goes on the parent. The@md:variants go on descendants. An element cannot query its own size. - Container variants respond to the nearest ancestor with
@container. If styles are not applying, check which container you are actually querying.
Variants
Tailwind v4 ships container queries in core. The sizes:
| Variant | Min width |
|---|---|
@3xs | 16rem (256px) |
@2xs | 18rem (288px) |
@xs | 20rem (320px) |
@sm | 24rem (384px) |
@md | 28rem (448px) |
@lg | 32rem (512px) |
@xl | 36rem (576px) |
@2xl | 42rem (672px) |
@3xl | 48rem (768px) |
@4xl | 56rem (896px) |
@5xl | 64rem (1024px) |
@6xl | 72rem (1152px) |
@7xl | 80rem (1280px) |
Also available:
@max-md:styles below a container size.@min-[475px]:arbitrary values when the scale does not fit.@container/sidebarplus@md/sidebar:flex-rowto name a container and query it from deeper in the tree, past other containers.
The full docs for this can be found here.
On Tailwind v3, the same syntax needs the @tailwindcss/container-queries plugin. Check the Tailwind version before writing classes.
When viewport breakpoints are still right
Do not convert these:
- Page-level layout. The overall grid, whether the sidebar exists at all, header and navigation behavior. These genuinely depend on the viewport.
- Fixed or sticky elements positioned relative to the viewport, like a bottom bar that becomes a side rail.
- Global typography scale tied to screen size.
Everything inside those layout regions, meaning cards, forms, media objects, stat blocks, table-to-list switches, should use container queries.
Migrating existing code
- Find the component's responsive classes (
sm:,md:,lg:). - Add
@containerto the component's root or the wrapper that owns the available space. - Replace viewport variants with the container variant that matches the actual width where the layout should change. Do not map
md:to@md:blindly;mdis 768px of viewport,@mdis 448px of container. Resize the container, not the window, to find the real breakpoint. - Test the component in its narrowest real context (sidebar, drawer, small grid cell), not just at mobile viewport widths.
Mistakes to catch in review
md:flex-rowon a component that is rendered inside a sidebar or modal. It will stay stacked or break depending on the viewport, not its actual space.@md:variants used with no@containerancestor. They silently never apply.@containerand a@md:variant on the same element. The element cannot query itself; move the variant to a child or the container class to the parent.- A component that only looks right at the exact spot it was built for. If moving it to a different column breaks it, it is viewport-coupled.
相关资源

daisyUI
SkilldaisyUI 官方技能,让 agent 编写 HTML 或 JSX 时使用 daisyUI 5 的组件类名、语义色与主题:先按功能挑选合适的组件并阅读对应文档,再按其结构与约束写代码,附带安装、用法、配置与颜色等子指南。基于 Tailwind CSS 4。
saadeghi/daisyui42.9k
Web Artifacts Builder
Skill用 React、Tailwind CSS 与 shadcn/ui 搭建需要状态管理或路由的多组件网页,自带初始化与打包脚本,最终打包成单个 HTML 文件作为 claude.ai Artifact。Anthropic 官方技能。
anthropics/skills197k
shadcn/ui
Skillshadcn/ui 官方技能:让 agent 借助 shadcn CLI 读取项目配置与组件文档,按规范添加、搜索、组合和修复组件,遵守样式、表单与无障碍规则,也能用预设初始化新项目。
shadcn-ui/ui128k
daisyUI Config
SkilldaisyUI 5 的配置说明:在 CSS 的 daisyUI 插件块中设置启用哪些主题、默认主题与深色模式主题、根选择器、包含或排除的模块、类名前缀和控制台日志,并附完整示例。daisyUI 官方技能的子指南。
saadeghi/daisyui42.9k
Animation On Scroll
Skill用 IntersectionObserver 加 Tailwind 任意值动画类实现元素进入视口时的入场动画,给出关键帧与观察器代码片段,可调整触发阈值、rootMargin、时长、延迟以及是否只播放一次。
MengTo/Skills7.7k
Tailwind CSS
Skill用 Tailwind CSS 实现界面的通用指南:响应式与状态变体、深色模式、克制使用任意值、优先拆组件再用 @apply,以及动态拼接类名导致生产环境缺样式等常见问题,附按钮与首屏版式示例。
MengTo/Skills7.7k