Cusror Tailwind CSS 最佳rules实践

161 阅读3分钟
  • tailwind
---
description: Tailwind CSS and UI component best practices for modern web applications
globs: **/*.css, **/*.tsx, **/*.jsx, tailwind.config.js, tailwind.config.ts
---

# Tailwind CSS Best Practices

## Project Setup
- Use proper Tailwind configuration
- Configure theme extension properly
- Set up proper purge configuration
- Use proper plugin integration
- Configure custom spacing and breakpoints
- Set up proper color palette

## Component Styling
- Use utility classes over custom CSS
- Group related utilities with @apply when needed
- Use proper responsive design utilities
- Implement dark mode properly
- Use proper state variants
- Keep component styles consistent

## Layout
- Use Flexbox and Grid utilities effectively
- Implement proper spacing system
- Use container queries when needed
- Implement proper responsive breakpoints
- Use proper padding and margin utilities
- Implement proper alignment utilities

## Typography
- Use proper font size utilities
- Implement proper line height
- Use proper font weight utilities
- Configure custom fonts properly
- Use proper text alignment
- Implement proper text decoration

## Colors
- Use semantic color naming
- Implement proper color contrast
- Use opacity utilities effectively
- Configure custom colors properly
- Use proper gradient utilities
- Implement proper hover states

## Components
- Use shadcn/ui components when available
- Extend components properly
- Keep component variants consistent
- Implement proper animations
- Use proper transition utilities
- Keep accessibility in mind

## Responsive Design
- Use mobile-first approach
- Implement proper breakpoints
- Use container queries effectively
- Handle different screen sizes properly
- Implement proper responsive typography
- Use proper responsive spacing

## Performance
- Use proper purge configuration
- Minimize custom CSS
- Use proper caching strategies
- Implement proper code splitting
- Optimize for production
- Monitor bundle size

## Best Practices
- Follow naming conventions
- Keep styles organized
- Use proper documentation
- Implement proper testing
- Follow accessibility guidelines
- Use proper version control 

Tailwind CSS 最佳实践

描述

现代 Web 应用程序的 Tailwind CSS 和 UI 组件最佳实践

适用范围

/.css, /.tsx, /.jsx, tailwind.config.js, tailwind.config.ts 目录下的所有文件

项目设置

  • 使用适当的 Tailwind 配置
  • 正确配置主题扩展
  • 设置适当的清除配置
  • 使用适当的插件集成
  • 配置自定义间距和断点
  • 设置适当的调色板

组件样式

  • 使用工具类而不是自定义 CSS
  • 需要时使用 @apply 组合相关工具类
  • 使用适当的响应式设计工具类
  • 正确实现暗黑模式
  • 使用适当的状态变体
  • 保持组件样式一致性

布局

  • 有效使用 Flexbox 和 Grid 工具类
  • 实现适当的间距系统
  • 需要时使用容器查询
  • 实现适当的响应式断点
  • 使用适当的内外边距工具类
  • 实现适当的对齐工具类

排版

  • 使用适当的字体大小工具类
  • 实现适当的行高
  • 使用适当的字重工具类
  • 正确配置自定义字体
  • 使用适当的文本对齐
  • 实现适当的文本装饰

颜色

  • 使用语义化的颜色命名
  • 实现适当的颜色对比度
  • 有效使用透明度工具类
  • 正确配置自定义颜色
  • 使用适当的渐变工具类
  • 实现适当的悬停状态

组件

  • 可用时使用 shadcn/ui 组件
  • 正确扩展组件
  • 保持组件变体一致性
  • 实现适当的动画
  • 使用适当的过渡工具类
  • 注意可访问性

响应式设计

  • 使用移动优先方法
  • 实现适当的断点
  • 有效使用容器查询
  • 正确处理不同屏幕尺寸
  • 实现适当的响应式排版
  • 使用适当的响应式间距

性能

  • 使用适当的清除配置
  • 最小化自定义 CSS
  • 使用适当的缓存策略
  • 实现适当的代码分割
  • 优化生产环境
  • 监控包大小

最佳实践

  • 遵循命名约定
  • 保持样式组织
  • 使用适当的文档
  • 实现适当的测试
  • 遵循可访问性指南
  • 使用适当的版本控制