全部学科
Python全栈
python
NodeJS全栈
nodejs
小程序首页
📅 2026-05-16 8 分钟 ✍️ juanwangdev

CSS文本样式

CSS文本属性用于控制文字的外观和排版,是页面内容呈现的核心。

字体属性

字体族与大小

CSS
.text {
  font-family: "Microsoft YaHei", Arial, sans-serif;
  font-size: 16px;
  font-weight: 400;    /* 100-900 或 normal/bold */
  font-style: normal;  /* normal/italic/oblique */
}

行高与字间距

CSS
.text {
  line-height: 1.6;
  letter-spacing: 2px;
  word-spacing: 4px;
}

文本颜色

CSS
.text {
  color: #333;
  color: rgb(51, 51, 51);
  color: rgba(51, 51, 51, 0.8);
}

文本对齐

CSS
.text {
  text-align: left;      /* left/center/right/justify */
  text-align-last: auto; /* 最后一行对齐方式 */
  vertical-align: middle; /* 垂直对齐 */
}

文本装饰

CSS
.text {
  text-decoration: none;           /* 去除下划线 */
  text-decoration: underline;      /* 下划线 */
  text-decoration: line-through;   /* 删除线 */
  text-decoration: overline;       /* 上划线 */
}

/* 组合写法 */
.text {
  text-decoration: underline wavy red;
}

文本缩进与换行

CSS
.text {
  text-indent: 2em;          /* 首行缩进 */
  white-space: nowrap;       /* 不换行 */
  white-space: pre-wrap;     /* 保留空白并换行 */
  word-break: break-all;      /* 允许单词内换行 */
  overflow-wrap: break-word;  /* 长单词换行 */
}

文本溢出处理

CSS
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;  /* 显示省略号 */
}

/* 多行省略 */
.multi-ellipsis {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

注意:text-overflow: ellipsis 需配合 white-space: nowrapoverflow: hidden 使用。

要点总结

  • font-family 建议指定多个备选字体
  • line-height 无单位时表示字体大小的倍数
  • 单行省略需三属性配合:white-space + overflow + text-overflow
  • text-decoration 可去除链接默认下划线

存放路径:articles/CSS/入门/CSS样式属性/CSS文本样式.md

📝 发现内容有误?点击此处直接编辑

← 上一篇 CSS动画与过渡
下一篇 → CSS背景与边框
想查看更多题目和详细解析?
小程序提供完整的题库、模拟考试和详细解析
马上就来

长按或扫描二维码,立即体验

扫码体验小程序
马上就来
使用微信扫描二维码
立即体验完整题库