Loading...
Loading...
Compare original and translation side by side
Non-negotiable design and user interface standards. These are not preferences—they are requirements.
不可协商的设计与用户界面标准。这些不是偏好——而是硬性要求。
web-accessibilityweb-cssweb-accessibilityweb-cssstyles/global.cssstyles/global.css/* ✅ Correct - Uses design tokens */
.button {
padding: var(--space-sm) var(--space-md);
font-size: var(--font-size-body);
background: var(--color-primary);
border-radius: var(--radius-sm);
box-shadow: var(--shadow-sm);
}
/* ❌ Wrong - Hardcoded values */
.button {
padding: 8px 16px; /* Use var(--space-sm) var(--space-md) */
font-size: 14px; /* Use var(--font-size-body) */
background: #3B82F6; /* Use var(--color-primary) */
border-radius: 4px; /* Use var(--radius-sm) */
}/* ✅ 正确示范 - 使用Design Token */
.button {
padding: var(--space-sm) var(--space-md);
font-size: var(--font-size-body);
background: var(--color-primary);
border-radius: var(--radius-sm);
box-shadow: var(--shadow-sm);
}
/* ❌ 错误示范 - 硬编码值 */
.button {
padding: 8px 16px; /* 应使用var(--space-sm) var(--space-md) */
font-size: 14px; /* 应使用var(--font-size-body) */
background: #3B82F6; /* 应使用var(--color-primary) */
border-radius: 4px; /* 应使用var(--radius-sm) */
}<header><nav><main><article><section><footer><button><a><form><label><input><select><textarea><ul><ol><li><h1><h2><h3>alt<header><nav><main><article><section><footer><button><a><form><label><input><select><textarea><ul><ol><li><h1><h2><h3>alt<!-- ✅ Good - Semantic HTML -->
<article class="product-card">
<header>
<h2>Product Name</h2>
</header>
<img src="..." alt="Product description">
<p>Product description goes here.</p>
<footer>
<button type="button">Add to Cart</button>
</footer>
</article>
<!-- ❌ Bad - Non-semantic divs -->
<div class="prd-crd">
<div class="hdr">
<div class="ttl">Product Name</div>
</div>
<div class="img"></div>
<div class="btn">Add to Cart</div>
</div><!-- ✅ 良好示范 - 语义化HTML -->
<article class="product-card">
<header>
<h2>产品名称</h2>
</header>
<img src="..." alt="产品描述">
<p>产品描述内容。</p>
<footer>
<button type="button">加入购物车</button>
</footer>
</article>
<!-- ❌ 不良示范 - 非语义化div -->
<div class="prd-crd">
<div class="hdr">
<div class="ttl">产品名称</div>
</div>
<div class="img"></div>
<div class="btn">加入购物车</div>
</div><h1><h6><!-- ❌ Wrong - Using heading for font size -->
<h3>Sale Price</h3> <!-- Not a section heading, just wants bold text -->
<!-- ✅ Right - Use a class for styling -->
<p class="price-label">Sale Price</p><h1><h6><!-- ❌ 错误示范 - 为字体大小使用标题标签 -->
<h3>促销价格</h3> <!-- 并非章节标题,只是需要粗体文本 -->
<!-- ✅ 正确示范 - 使用类进行样式设置 -->
<p class="price-label">促销价格</p><!-- ❌ Bad - Class soup -->
<button class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:ring-2">
Submit
</button>
<!-- ✅ Good - Semantic class (styling lives in CSS) -->
<button class="btn btn--primary">
Submit
</button><!-- ❌ 不良示范 - 类名堆砌 -->
<button class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:ring-2">
提交
</button>
<!-- ✅ 良好示范 - 语义化类名(样式定义在CSS中) -->
<button class="btn btn--primary">
提交
</button>// ❌ Bad - Inline styles
<div style={{ marginTop: '16px', padding: '8px' }}>
// ✅ Good - CSS class
<div className="card-section">// ❌ 不良示范 - 内联样式
<div style={{ marginTop: '16px', padding: '8px' }}>
// ✅ 良好示范 - CSS类名
<div className="card-section">/* ✅ Good - Human-readable */
.product-card {
display: flex;
flex-direction: column;
gap: var(--space-md);
padding: var(--space-lg);
background-color: var(--color-neutral-50);
border-radius: var(--radius-md);
box-shadow: var(--shadow-sm);
}
.product-card:hover {
box-shadow: var(--shadow-md);
transform: translateY(-2px);
transition: all var(--duration-fast) var(--easing-standard);
}/* ✅ 良好示范 - 易于人类阅读 */
.product-card {
display: flex;
flex-direction: column;
gap: var(--space-md);
padding: var(--space-lg);
background-color: var(--color-neutral-50);
border-radius: var(--radius-md);
box-shadow: var(--shadow-sm);
}
.product-card:hover {
box-shadow: var(--shadow-md);
transform: translateY(-2px);
transition: all var(--duration-fast) var(--easing-standard);
}| State | Requirement | Example |
|---|---|---|
| Default | Base appearance | Normal button |
| Hover | Visual feedback on mouse over | Background darkens |
| Active | Visual feedback when pressed | Slight scale down |
| Focus | Clear focus indicator (keyboard nav) | |
| Disabled | Visually distinct, non-interactive | Grayed out, low opacity |
| 状态 | 要求 | 示例 |
|---|---|---|
| 默认 | 基础外观 | 普通按钮 |
| Hover | 鼠标悬停时的视觉反馈 | 背景加深 |
| Active | 按下时的视觉反馈 | 轻微缩小 |
| Focus | 清晰的焦点指示器(键盘导航) | |
| Disabled | 视觉区分明显,不可交互 | 灰度化,低透明度 |
| Layout Need | Tool | Example |
|---|---|---|
| Page structure | Grid (named areas) | Header, sidebar, main, footer |
| Section layout | Grid (named areas) | Two-column content, form layout |
| Component structure | Grid (named areas) | Card internals, modal layout |
| Navigation items | Flexbox | Top nav items, menu items |
| Gallery/flowing items | Flexbox | Image grid, card gallery, tag list |
| 布局需求 | 工具 | 示例 |
|---|---|---|
| 页面结构 | Grid(命名区域) | 页眉、侧边栏、主内容区、页脚 |
| 章节布局 | Grid(命名区域) | 两栏内容、表单布局 |
| 组件结构 | Grid(命名区域) | 卡片内部结构、模态框布局 |
| 导航项 | Flexbox | 顶部导航项、菜单项 |
| 画廊/流式项目 | Flexbox | 图片网格、卡片画廊、标签列表 |
#app-layout {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
gap: var(--space-md);
}
#header { grid-area: header; }
#sidebar { grid-area: sidebar; }
#main { grid-area: main; }
#footer { grid-area: footer; }#app-layout {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
gap: var(--space-md);
}
#header { grid-area: header; }
#sidebar { grid-area: sidebar; }
#main { grid-area: main; }
#footer { grid-area: footer; }@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}/* Mobile: 0-767px (base styles, no media query needed) */
/* Tablet: 768px and up */
@media (min-width: 768px) { }
/* Desktop: 1024px and up */
@media (min-width: 1024px) { }
/* Large Desktop: 1280px and up */
@media (min-width: 1280px) { }@media (max-width: ...)/* 移动端:0-767px(基础样式,无需媒体查询) */
/* 平板:768px及以上 */
@media (min-width: 768px) { }
/* 桌面端:1024px及以上 */
@media (min-width: 1024px) { }
/* 大桌面端:1280px及以上 */
@media (min-width: 1280px) { }@media (max-width: ...)| Anti-Pattern | Why Bad | Do Instead |
|---|---|---|
| Floating labels | Confusing | Labels above inputs |
| Inline validation | Annoying | Validate on blur/submit |
| Generic error messages | Unhelpful | Specific, actionable errors |
| Tooltips for critical info | Easy to miss | Show directly |
| Disabled buttons without explanation | Frustrating | Show why disabled |
| Custom scrollbars | Inconsistent UX | System scrollbars |
| Hamburger menu on desktop | Hides navigation | Full nav on desktop |
| 反模式 | 危害 | 正确做法 |
|---|---|---|
| 浮动标签 | 易混淆 | 标签置于输入框上方 |
| 实时内联验证 | 烦人 | 在失焦/提交时验证 |
| 通用错误提示 | 无帮助 | 具体、可操作的错误信息 |
| 关键信息使用工具提示 | 易被忽略 | 直接显示信息 |
| 无说明的禁用按钮 | 令人沮丧 | 显示禁用原因 |
| 自定义滚动条 | 用户体验不一致 | 使用系统滚动条 |
| 桌面端使用汉堡菜单 | 隐藏导航 | 桌面端显示完整导航 |
references/semantic-html.mdreferences/css-formatting.mdreferences/accessibility-guide.mdreferences/responsive-breakpoints.mdreferences/semantic-html.mdreferences/css-formatting.mdreferences/accessibility-guide.mdreferences/responsive-breakpoints.mdassets/component-states-checklist.mdassets/anti-patterns.mdassets/layout-examples.mdassets/component-states-checklist.mdassets/anti-patterns.mdassets/layout-examples.mdscripts/validate_design_tokens.pyscripts/check_accessibility.pyscripts/validate_design_tokens.pyscripts/check_accessibility.py