🧪 Frontend Lab
交互式前端学习实验室

CSS 排版:博客文章

css · beginner · 15-20 min · Step 1/5

CSS 排版

核心属性

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;        /* 基础字号 */
  line-height: 1.6;       /* 行高(无单位 = 相对字号倍数) */
  letter-spacing: 0.02em; /* 字间距 */
}

h1 { font-size: 2.5rem; }  /* 40px */
h2 { font-size: 2rem; }    /* 32px */
h3 { font-size: 1.5rem; }  /* 24px */

文本截断

/* 单行截断 */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 多行截断 */
.clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
规则:正文 line-height 用 1.5-1.8,标题用 1.2-1.4。