Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2783

container-queries

Skill này làm gì

Skill này cho thấy cách dùng container query, một tính năng CSS thay đổi bố cục của component dựa trên chiều rộng của phần tử cha. Skill dành cho lập trình viên front end xây component có thể tái sử dụng.

Khi nào nên dùng

  • ✓Khi một thẻ hoặc widget bị vỡ trong thanh bên nhưng vẫn ổn ở cột chính.
  • ✓Khi bạn xây một component sẽ xuất hiện trong nhiều bố cục khác nhau.
  • ✓Khi media query của bạn chỉ định kiểu component theo chiều rộng màn hình.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/container-queries/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/container-queries/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thẻ sản phẩm của tôi bị vỡ khi đặt trong thanh bên. Hãy làm nó điều chỉnh theo vùng chứa thay vì màn hình.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent đặt container-type trên phần tử cha và viết các quy tắc container query áp dụng khi vùng chứa đạt một số chiều rộng nhất định.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Use container queries for component-level responsiveness

Media queries respond to viewport width, which makes components context-dependent — a card designed for a 3-column grid might break when placed in a 2-column grid or a sidebar. Container queries solve this: a card can layout itself based on how much space its container gives it, making the component genuinely reusable in any layout context.

Quick Reference

  • Container queries respond to the parent container's size, not the viewport
  • Set container-type: inline-size on the parent to enable container queries
  • Use @container rule to write styles that activate at container breakpoints
  • Container queries make components reusable in sidebars, grids, and full-width areas

Check

Look for components in this CSS that have media query breakpoints — consider whether container queries would make them more reusable in different layout contexts.

Fix

Convert this component from media query-based to container query-based responsiveness using container-type and @container.

Explain

Explain how container queries differ from media queries, why they enable better component reuse, and how to set up the container/query relationship.

Code Review

Review stylesheets, component styles, and responsive states related to Use container queries for component-level responsiveness. Flag exact selectors, declarations, or breakpoints that violate the rule in the rendered UI.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/css/container-queries

Câu hỏi thường gặp

Container query khác media query thế nào?

Skill nói nó phản ứng với kích thước của phần tử cha, không phải chiều rộng viewport.

Phần tử cha cần thiết lập gì?

Skill nói container-type được đặt thành inline-size.

Vì sao điều này giúp tái sử dụng?

Skill nói các component có thể tự bố trí cho thanh bên, lưới và vùng toàn chiều rộng.

Chi tiết

Mô tả gốc của tác giả

Use when reviewing stylesheets, component styles, and responsive behavior related to Use container queries for component-level responsiveness. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2783
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự