| name | html-css-responsive-design |
| description | null |
Responsive Design
Category: html-css · Status: 🟢 Active
When to use
Khi cần giao diện thích ứng nhiều kích thước màn hình.
Steps
- Viết mobile-first: style mặc định cho mobile,
min-width media query để mở rộng.
- Chọn breakpoint theo nội dung (chỗ layout vỡ), không theo tên thiết bị.
- Dùng
clamp(min, fluid, max) cho font/spacing để co giãn mượt, giảm media query.
- Layout fluid bằng
%, fr, minmax; tránh chiều rộng pixel cố định.
- Đặt ảnh
max-width: 100%; height: auto; dùng srcset cho ảnh nặng.
- Test ở viewport hẹp nhất và rộng nhất, kiểm tra nội dung dài/ngắn.
Template
:root { --container: min(100% - 2rem, 1200px); }
.title { font-size: clamp(1.5rem, 1rem + 2vw, 2.5rem); }
.layout { width: var(--container); margin-inline: auto; }
@media (min-width: 48rem) {
.layout { display: grid; grid-template-columns: 1fr 2fr; }
}
Example
Good: mobile-first, clamp() cho font, breakpoint đặt khi layout vỡ.
Avoid: desktop-first max-width, width: 980px cứng, breakpoint cứng theo iPhone.
Checklist