Joevan's

PureText CSS 设计系统

PureText CSS 设计系统

1. 设计令牌 (Design Tokens)

:root {
  /* 色彩系统 - 只有黑白灰 */
  --color-black: #000000;
  --color-gray-90: #111111;
  --color-gray-80: #222222;
  --color-gray-70: #333333;
  --color-gray-60: #444444;
  --color-gray-50: #666666;
  --color-gray-40: #888888;
  --color-gray-30: #aaaaaa;
  --color-gray-20: #cccccc;
  --color-gray-10: #e5e5e5;
  --color-gray-5:  #f2f2f2;
  --color-white:  #ffffff;
  
  /* 功能色 - 仅在暗色模式需要 */
  --color-error:  #cc3333;
  --color-success: #33aa33;
  
  /* 间距系统 - 基于 8px 网格 */
  --space-0: 0;
  --space-1: 0.125rem;  /* 2px */
  --space-2: 0.25rem;   /* 4px */
  --space-3: 0.5rem;    /* 8px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.5rem;    /* 24px */
  --space-6: 2rem;      /* 32px */
  --space-7: 3rem;      /* 48px */
  --space-8: 4rem;      /* 64px */
  
  /* 字体系统 - 无衬线优先,serif 回退 */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-serif: Georgia, 'Times New Roman', Times, serif;
  --font-mono: 'SF Mono', Monaco, 'Courier New', monospace;
  
  /* 字号系统 - 限制在 5 种尺寸内 */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */
  --text-4xl: 2.25rem;   /* 36px */
  
  /* 行高 */
  --leading-none: 1;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-loose: 1.75;
  
  /* 最大内容宽度 */
  --max-width-xs: 20rem;     /* 320px */
  --max-width-sm: 30rem;     /* 480px */
  --max-width-md: 40rem;     /* 640px */
  --max-width-lg: 50rem;     /* 800px */
  --max-width-xl: 60rem;     /* 960px */
  --max-width-full: 100%;
  
  /* 边框 */
  --border-none: 0;
  --border-thin: 1px solid var(--color-gray-20);
  --border-thick: 2px solid var(--color-black);
}

2. 重置与基础样式

/* 彻底的基础重置 */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 16px;
}

body {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-black);
  background-color: var(--color-white);
  overflow-x: hidden;
  min-height: 100vh;
}

/* 链接 - 只有下划线 */
a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  background-color: transparent;
  -webkit-text-decoration-skip: objects;
}

a:hover {
  text-decoration: none;
}

/* 标题 - 只有字重和大小 */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: var(--leading-tight);
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

/* 段落和列表 */
p {
  margin-bottom: var(--space-4);
}

ul, ol {
  padding-left: var(--space-5);
  margin-bottom: var(--space-4);
}

li {
  margin-bottom: var(--space-1);
}

/* 代码块 */
code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background-color: var(--color-gray-5);
}

pre {
  padding: var(--space-3);
  overflow-x: auto;
  margin-bottom: var(--space-4);
  border-left: 3px solid var(--color-gray-20);
}

code {
  padding: var(--space-1) var(--space-2);
}

3. 布局系统

/* 容器 */
.container {
  width: 100%;
  max-width: var(--max-width-lg);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

@media (max-width: 768px) {
  .container {
    max-width: var(--max-width-full);
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

/* 网格 - 最简单的两列系统 */
.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* 弹性布局工具 */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-row {
  flex-direction: row;
}

.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }

.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }

.gap-0 { gap: var(--space-0); }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

4. 组件样式

/* 按钮 - 只有方括号 */
[class*="btn-"] {
  display: inline-block;
  font: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.btn {
  /* 方括号通过伪元素实现 */
  position: relative;
  padding-left: var(--space-3);
  padding-right: var(--space-3);
}

.btn::before {
  content: '[';
  position: absolute;
  left: 0;
  top: 0;
}

.btn::after {
  content: ']';
  position: absolute;
  right: 0;
  top: 0;
}

.btn:hover::before,
.btn:hover::after {
  content: ''; /* 悬停时去掉方括号 */
}

/* 输入框 */
.input {
  width: 100%;
  font: inherit;
  background: var(--color-white);
  border: var(--border-thin);
  padding: var(--space-2) var(--space-3);
  color: var(--color-black);
  appearance: none;
  -webkit-appearance: none;
  border-radius: 0; /* 坚决不要圆角 */
}

.input:focus {
  outline: none;
  border: var(--border-thick);
  padding: calc(var(--space-2) - 1px) calc(var(--space-3) - 1px);
  /* 边框加粗时保持内容位置不变 */
}

/* 文本域 */
.textarea {
  min-height: 8rem;
  resize: vertical;
  line-height: var(--leading-normal);
  font-family: var(--font-sans);
}

/* 分隔线 - 只有横线 */
.divider {
  height: 1px;
  background: var(--color-gray-20);
  border: none;
  margin: var(--space-6) 0;
}

/* 文章卡片 - 最简单的时间线 */
.article {
  margin-bottom: var(--space-6);
}

.article-date {
  font-size: var(--text-sm);
  color: var(--color-gray-40);
  font-family: var(--font-mono);
  margin-bottom: var(--space-2);
}

.article-title {
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--space-2);
  line-height: var(--leading-tight);
}

.article-title a {
  text-decoration: none;
}

.article-title a:hover {
  text-decoration: underline;
}

.article-content {
  font-family: var(--font-serif);
  line-height: var(--leading-normal);
  color: var(--color-gray-70);
}

5. 实用工具类

/* 间距 - 只提供必要的几种 */
.m-0 { margin: var(--space-0); }
.m-2 { margin: var(--space-2); }
.m-4 { margin: var(--space-4); }
.m-6 { margin: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-0 { padding: var(--space-0); }
.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* 文字 */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }

.font-sans { font-family: var(--font-sans); }
.font-serif { font-family: var(--font-serif); }
.font-mono { font-family: var(--font-mono); }

.font-normal { font-weight: 400; }
.font-bold { font-weight: 700; }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* 显示 */
.hidden { display: none; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }

/* 宽度 */
.w-full { width: 100%; }
.w-auto { width: auto; }
.max-w-full { max-width: 100%; }
.max-w-lg { max-width: var(--max-width-lg); }
.max-w-md { max-width: var(--max-width-md); }
.max-w-sm { max-width: var(--max-width-sm); }

6. 暗色模式

/* 系统级暗色模式 */
@media (prefers-color-scheme: dark) {
  :root {
    --color-black: #ffffff;
    --color-gray-90: #f2f2f2;
    --color-gray-80: #e5e5e5;
    --color-gray-70: #cccccc;
    --color-gray-60: #aaaaaa;
    --color-gray-50: #888888;
    --color-gray-40: #666666;
    --color-gray-30: #444444;
    --color-gray-20: #333333;
    --color-gray-10: #222222;
    --color-gray-5:  #1a1a1a;
    --color-white:  #111111;
  }
  
  body {
    color: var(--color-black);
    background-color: var(--color-white);
  }
  
  code, pre {
    background-color: var(--color-gray-5);
  }
}

7. 响应式断点

/* 移动优先 - 只有一个断点 */
@media (min-width: 768px) {
  .md\:grid-2 {
    grid-template-columns: 1fr 1fr;
  }
  
  .md\:flex-row {
    flex-direction: row;
  }
  
  .md\:text-lg {
    font-size: var(--text-lg);
  }
  
  .md\:max-w-lg {
    max-width: var(--max-width-lg);
  }
}

8. 性能优化

/* 打印样式 */
@media print {
  * {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: var(--text-sm);
  }
  
  .no-print {
    display: none;
  }
}

/* 减少动画和过渡 */
* {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* 焦点样式 - 必须保留可访问性 */
:focus-visible {
  outline: 2px solid var(--color-black);
  outline-offset: 2px;
}

使用规范

  1. 文件大小:整个CSS不超过1KB(压缩后)
  2. 选择器深度:不超过2级嵌套
  3. 无!important:禁止使用
  4. 无浮动:使用flex或grid布局
  5. 无固定高度:使用min-height
  6. 无z-index:通过DOM顺序控制层叠
  7. 无背景图:使用纯色
  8. 无变换:避免transform和filter
  9. 无自定义字体:使用系统字体
  10. 无圆角:坚持直角设计

文件结束 | 版本:1.0 | 大小:3.5KB (未压缩)