tailwind-responsive-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommunity Responsive UI Tailwind CSS Best Practices
社区版Tailwind CSS响应式UI最佳实践
Comprehensive responsive transformation guide for Tailwind CSS applications, based on Refactoring UI by Adam Wathan & Steve Schoger and modern responsive design patterns. Contains 49 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
这是一份针对Tailwind CSS应用的全面响应式转换指南,基于Adam Wathan和Steve Schoger所著的《Refactoring UI》以及现代响应式设计模式编写。指南包含8个类别下的49条规则,按影响优先级排序,可用于指导自动化重构与代码生成。
When to Apply
适用场景
Reference these guidelines when:
- Making an existing UI responsive across screen sizes
- Building new responsive layouts with Tailwind CSS
- Refactoring desktop-only interfaces for mobile support
- Reviewing responsive code for breakpoint, spacing, and typography issues
- Adapting navigation, forms, and data tables for touch devices
在以下场景中可参考本指南:
- 为现有UI实现跨屏幕尺寸的响应式适配
- 使用Tailwind CSS构建全新的响应式布局
- 重构仅支持桌面端的界面以适配移动端
- 审查响应式代码中的断点、间距与排版问题
- 为触控设备适配导航、表单与数据表格
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Breakpoint Strategy | CRITICAL | |
| 2 | Layout Transformation | CRITICAL | |
| 3 | Responsive Spacing | HIGH | |
| 4 | Fluid Typography | HIGH | |
| 5 | Navigation Patterns | MEDIUM-HIGH | |
| 6 | Touch & Interaction | MEDIUM | |
| 7 | Responsive Media | MEDIUM | |
| 8 | Data Adaptation | LOW-MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 断点策略 | 关键 | |
| 2 | 布局转换 | 关键 | |
| 3 | 响应式间距 | 高 | |
| 4 | 流体排版 | 高 | |
| 5 | 导航模式 | 中高 | |
| 6 | 触摸与交互 | 中 | |
| 7 | 响应式媒体 | 中 | |
| 8 | 数据适配 | 中低 | |
Quick Reference
快速参考
1. Breakpoint Strategy (CRITICAL)
1. 断点策略(关键)
- - Use Mobile-First Breakpoint Direction
bp-mobile-first-default - - Set Breakpoints Where Content Breaks
bp-content-driven-breakpoints - - Avoid Device-Specific Breakpoint Values
bp-avoid-device-widths - - Consolidate Breakpoints to Three or Four
bp-consolidate-breakpoints - - Use min-width Over max-width for Breakpoints
bp-min-width-over-max - - Use Visual Breakpoint Indicators During Development
bp-debug-breakpoints
- - 采用移动端优先的断点方向
bp-mobile-first-default - - 基于内容断点设置适配节点
bp-content-driven-breakpoints - - 避免使用设备特定的断点值
bp-avoid-device-widths - - 将断点合并为3到4个
bp-consolidate-breakpoints - - 优先使用min-width而非max-width设置断点
bp-min-width-over-max - - 开发期间使用可视化断点指示器
bp-debug-breakpoints
2. Layout Transformation (CRITICAL)
2. 布局转换(关键)
- - Stack Elements on Mobile, Row on Desktop
layout-stack-to-row - - Collapse Sidebar to Top or Bottom on Mobile
layout-sidebar-collapse - - Reduce Grid Columns at Narrower Breakpoints
layout-grid-column-reduction - - Use Responsive Holy Grail Layout with Grid
layout-holy-grail-responsive - - Convert Sticky Elements to Static on Mobile
layout-sticky-to-static - - Replace Fixed Positioning with Relative on Mobile
layout-fixed-to-relative - - Use Aspect Ratio for Responsive Containers
layout-aspect-ratio-containers
- - 移动端采用堆叠布局,桌面端采用行布局
layout-stack-to-row - - 移动端将侧边栏折叠为顶部或底部导航
layout-sidebar-collapse - - 在窄屏断点下减少网格列数
layout-grid-column-reduction - - 使用Grid实现响应式圣杯布局
layout-holy-grail-responsive - - 移动端将粘性元素转换为静态定位
layout-sticky-to-static - - 移动端用相对定位替代固定定位
layout-fixed-to-relative - - 使用宽高比实现响应式容器
layout-aspect-ratio-containers
3. Responsive Spacing (HIGH)
3. 响应式间距(高)
- - Scale Padding Independently Per Breakpoint
rspac-scale-padding-per-bp - - Use Responsive Gap for Grid and Flex Spacing
rspac-responsive-gap - - Use Compact Spacing on Mobile, Generous on Desktop
rspac-compact-mobile-generous-desktop - - Scale Section Dividers with Viewport
rspac-section-spacing - - Convert Inline Spacing to Stack Spacing on Mobile
rspac-inline-to-stack-spacing - - Use Responsive Container Padding
rspac-container-padding
- - 为每个断点独立设置内边距缩放比例
rspac-scale-padding-per-bp - - 为Grid和Flex布局使用响应式间距
rspac-responsive-gap - - 移动端采用紧凑间距,桌面端采用宽松间距
rspac-compact-mobile-generous-desktop - - 随视窗大小调整区块分隔间距
rspac-section-spacing - - 移动端将内联间距转换为堆叠间距
rspac-inline-to-stack-spacing - - 使用响应式容器内边距
rspac-container-padding
4. Fluid Typography (HIGH)
4. 流体排版(高)
- - Use clamp() for Fluid Font Sizing
fluid-clamp-font-size - - Tighten Line Height as Font Size Increases
fluid-responsive-line-height - - Constrain Line Length to 45-75 Characters
fluid-responsive-measure - - Scale Heading Sizes Independently Across Breakpoints
fluid-scale-headings-independently - - Adjust Letter Spacing for Responsive Headlines
fluid-responsive-letter-spacing - - Use a Responsive Type Scale
fluid-type-scale
- - 使用clamp()实现流体字体大小
fluid-clamp-font-size - - 字体大小增大时收紧行高
fluid-responsive-line-height - - 将行长度限制在45-75个字符
fluid-responsive-measure - - 为不同断点独立调整标题大小
fluid-scale-headings-independently - - 为响应式标题调整字间距
fluid-responsive-letter-spacing - - 使用响应式字体比例
fluid-type-scale
5. Navigation Patterns (MEDIUM-HIGH)
5. 导航模式(中高)
- - Collapse Horizontal Nav to Hamburger on Mobile
nav-horizontal-to-hamburger - - Use Bottom Tab Bar for Primary Mobile Navigation
nav-tab-bar-mobile - - Truncate Breadcrumbs on Mobile
nav-breadcrumb-collapse - - Convert Sidebar Nav to Off-Canvas Drawer on Mobile
nav-sidebar-drawer - - Expand Dropdown Menus to Full-Width on Mobile
nav-dropdown-to-fullscreen - - Compact the Header on Scroll for Mobile
nav-sticky-header-compact
- - 移动端将水平导航折叠为汉堡菜单
nav-horizontal-to-hamburger - - 移动端使用底部标签栏作为主导航
nav-tab-bar-mobile - - 移动端截断面包屑导航
nav-breadcrumb-collapse - - 移动端将侧边栏导航转换为侧滑抽屉
nav-sidebar-drawer - - 移动端将下拉菜单展开为全屏样式
nav-dropdown-to-fullscreen - - 移动端滚动时收缩头部导航
nav-sticky-header-compact
6. Touch & Interaction (MEDIUM)
6. 触摸与交互(中)
- - Ensure Minimum 44px Touch Targets on Mobile
touch-min-touch-target - - Replace Hover Interactions with Tap-Friendly Alternatives
touch-hover-to-tap - - Add Visual Swipe Affordances for Horizontal Scrolling
touch-swipe-affordance - - Use Scroll Snap for Carousel-Like Mobile Interfaces
touch-scroll-snap-mobile - - Size Form Inputs to Prevent iOS Zoom
touch-input-sizing-mobile - - Use focus-visible for Touch-Friendly Focus Styles
touch-focus-visible-touch
- - 确保移动端触摸目标最小尺寸为44px
touch-min-touch-target - - 用适合点击的交互替代悬停交互
touch-hover-to-tap - - 为水平滚动添加视觉滑动提示
touch-swipe-affordance - - 移动端使用滚动吸附实现类轮播交互
touch-scroll-snap-mobile - - 调整表单输入框尺寸以避免iOS自动缩放
touch-input-sizing-mobile - - 使用focus-visible实现适合触摸的焦点样式
touch-focus-visible-touch
7. Responsive Media (MEDIUM)
7. 响应式媒体(中)
- - Use Responsive Image Sizing with Object-Fit
rmedia-responsive-images - - Maintain Video Aspect Ratio Across Breakpoints
rmedia-video-aspect-ratio - - Scale Icons Per Breakpoint, Not with Font Size
rmedia-icon-size-scaling - - Scale Avatar Sizes Per Context and Breakpoint
rmedia-avatar-responsive - - Swap Background Images at Breakpoints
rmedia-background-image-bp - - Make Embedded Content Responsive with Container Constraints
rmedia-embed-responsive
- - 使用Object-Fit实现响应式图片尺寸适配
rmedia-responsive-images - - 确保视频在各断点下保持宽高比
rmedia-video-aspect-ratio - - 为每个断点单独缩放图标尺寸,而非随字体大小调整
rmedia-icon-size-scaling - - 根据场景和断点调整头像尺寸
rmedia-avatar-responsive - - 在断点处切换背景图片
rmedia-background-image-bp - - 通过容器约束实现嵌入式内容的响应式适配
rmedia-embed-responsive
8. Data Adaptation (LOW-MEDIUM)
8. 数据适配(中低)
- - Transform Tables to Cards on Mobile
data-table-to-cards - - Use Horizontal Scroll for Dense Data Tables
data-horizontal-scroll-table - - Adapt Data Grid Density for Screen Size
data-responsive-data-grid - - Increase List Item Density on Mobile
data-list-density-mobile - - Truncate Overflowing Text on Mobile
data-truncate-overflow - - Stack Form Fields on Mobile, Use Grid on Desktop
data-responsive-form-layout
- - 移动端将表格转换为卡片布局
data-table-to-cards - - 为密集型数据表格使用水平滚动
data-horizontal-scroll-table - - 根据屏幕尺寸调整数据网格密度
data-responsive-data-grid - - 移动端提升列表项密度
data-list-density-mobile - - 移动端截断溢出文本
data-truncate-overflow - - 移动端采用堆叠表单字段,桌面端采用网格布局
data-responsive-form-layout
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
阅读单个参考文件获取详细说明与代码示例:
- 类别定义 - 类别结构与影响等级说明
- 规则模板 - 添加新规则的模板
Reference Files
参考文件
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
| 文件 | 描述 |
|---|---|
| references/_sections.md | 类别定义与排序说明 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本与参考信息 |