Skill站外收录 @skilllib/skill-2014279418401730561
standards-css
确保 CSS 编写符合项目规范,统一采用 Tailwind、BEM 或 CSS Modules 等既定方法论,优先使用设计系统中的颜色、间距、字体等 token,避免硬编码值与样式覆盖,通过工具链实现自动裁剪和按需加载,提升可维护性与运行时性能。
测试与安全 AI 技能
Skills.MD
# CSS Standards
**Rule:** Follow project CSS methodology consistently, leverage framework patterns, maintain design system tokens.
## When to use this skill
- When writing or modifying CSS files (.css, .scss, .sass, .less, .module.css)
- When applying utility classes in Tailwind CSS or similar utility-first frameworks
- When implementing CSS-in-JS or styled-components in React/Vue/Svelte components
- When defining or using design tokens (colors, spacing, typography, shadows)
- When maintaining consistency with the project's CSS methodology (BEM, OOCSS, SMACSS, utility-first)
- When optimizing CSS for production with purging or tree-shaking unused styles
- When avoiding excessive framework style overrides by working with framework patterns
- When implementing global styles or theme configurations
- When refactoring inline styles or scattered CSS into organized, maintainable patterns
- When establishing or following CSS naming conventions for the project
This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle frontend CSS.
## Identify Project Methodology First
Before writing any styles, check existing codebase for:
**Utility-first (Tailwind/UnoCSS):**
```jsx
<div className="flex items-center gap-4 p-6 bg-white rounded-lg shadow-md">
```
**CSS Modules:**
```jsx
import styles from './Component.module.css'
<div className={styles.container}>
```
**BEM (Block Element Modifier):**
```css
.card { }
.card__header { }
.card__header--highlighted { }
```
**CSS-in-JS (styled-components/emotion):**
```jsx
const Button = styled.button`
padding: 1rem;
background: ${props => props.theme.primary};
`
```
**Once identified, use that methodology exclusively. Never mix methodologies.**
## Design System Tokens
**Always use design tokens instead of hardcoded values:**
Bad:
```css
color: #3b82f6;
padding: 16px;
font-size: 14px;
```
Good (Tailwind):
```jsx
className="text-blue-500 p-4 text-sm"
```
Good (CSS variables):
```css
color: var(--color-primary);
padding: var(--spacing-4);
font-size: var(--text-sm);
```
**Check for existing tokens before creating new ones:**
1. Search for color/spacing/typography definitions
2. Use existing tokens if available
3. Only create new tokens if genuinely needed
4. Document new tokens in design system file
## Framework Patterns Over Overrides
**Work with framework, not against it:**
Bad (fighting Tailwind):
```jsx
<div className="flex items-center" style={{gap: '17px', padding: '13px'}}>
```
Good (using framework values):
```jsx
<div className="flex items-center gap-4 p-3">
```
Bad (overriding component library):
```css
.MuiButton-root {
padding: 12px !important;
background: red !important;
}
```
Good (using component API):
```jsx
<Button sx={{ padding: 3, bgcolor: 'error.main' }}>
```
**If you need `!important` or deep style overrides, reconsider your approach.**
## Minimize Custom CSS
**Prefer framework utilities over custom CSS:**
Bad:
```css
.custom-card {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1.5rem;
background: white;
border-radius: 0.5rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
```
Good (Tailwind):
```jsx
<div className="flex flex-col gap-4 p-6 bg-white rounded-lg shadow-sm">
```
**Only write custom CSS for:**
- Complex animations
- Unique visual effects not in framework
- Third-party library integration
- Browser-specific fixes
## Naming Conventions
**Follow project convention consistently:**
BEM:
```css
.block-name { }
.block-name__element { }
.block-name--modifier { }
```
CSS Modules (camelCase):
```css
.cardContainer { }
.cardHeader { }
.isActive { }
```
Utility-first (descriptive class names for custom components):
```css
.prose-headings { }
.custom-scrollbar { }
```
## Organization Patterns
**Structure CSS logically:**
```css
/* 1. Layout */
.component {
display: flex;
position: relative;
}
/* 2. Box model */
.component {
width: 100%;
padding: 1rem;
margin: 0 auto;
}
/* 3. Typography */
.component {
font-size: 1rem;
line-height: 1.5;
}
/* 4. Visual */
.component {
color: var(--text-primary);
background: var(--bg-surface);
border-radius: 0.5rem;
}
/* 5. Misc */
.component {
cursor: pointer;
transition: all 0.2s;
}
```
**Group related styles, separate concerns with comments.**
## Performance Optimization
**Production CSS should be optimized:**
Tailwind (purge unused):
```js
// tailwind.config.js
module.exports = {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
// Only includes classes actually used
}
```
CSS Modules (automatic tree-shaking):
```js
// Unused styles automatically removed in production
```
**Avoid:**
- Importing entire CSS frameworks when using few components
- Duplicate style definitions across files
- Overly specific selectors (`.a .b .c .d .e`)
- Large inline styles that could be extracted
## Common Mistakes
**Mixing methodologies:**
```jsx
// BAD - mixing Tailwind with inline styles and CSS modules
<div className={`${styles.card} flex p-4`} style={{gap: '12px'}}>
```
**Hardcoding values:**
```css
/* BAD */
color: #3b82f6;
padding: 17px;
/* GOOD */
color: var(--color-primary);
padding: var(--spacing-4);
```
**Fighting framework:**
```css
/* BAD */
.override {
margin: 13px !important;
}
/* GOOD - use framework's spacing scale */
className="m-3"
```
## Verification Checklist
Before completing CSS work:
- [ ] Identified and followed project CSS methodology
- [ ] Used design tokens instead of hardcoded values
- [ ] Leveraged framework utilities where possible
- [ ] Avoided `!important` and deep overrides
- [ ] Followed project naming conventions
- [ ] Organized styles logically
- [ ] Verified no unused styles in production build
- [ ] Tested visual output in browser
## Quick Reference
| Situation | Action |
| ------------------------------ | ------------------------------------- |
| New component styling | Check existing patterns first |
| Need specific color | Use design token, not hex code |
| Framework doesn't have utility | Write minimal custom CSS |
| Styles not applying | Check specificity, avoid `!important` |
| Large CSS file | Extract to utilities or components |
| Production bundle large | Enable CSS purging/tree-shaking |
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「standards-css」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次