目录

CSS 文本间距


文本间距

在本章中,您将了解以下属性:

  • text-indent
  • letter-spacing
  • line-height
  • word-spacing
  • white-space

文本缩进

这个text-indent属性用于指定文本第一行的缩进:

示例

p {
  text-indent: 50px;
}
亲自试一试 »

字母间距

这个letter-spacing属性用于指定文本中字符之间的间距。

以下示例演示如何增加或减少字符之间的间距:

示例

h1 {
  letter-spacing: 5px;
}

h2 {
  letter-spacing: -2px;
}
亲自试一试 »

行高

这个line-height属性用于指定行之间的间距:

示例

p.small {
  line-height: 0.8;
}

p.big {
  line-height: 1.8;
}
亲自试一试 »


字间距

这个word-spacing属性用于指定文本中单词之间的间距。

以下示例演示了如何增加或减少单词之间的间距:

示例

p.one {
  word-spacing: 10px;
}

p.two {
  word-spacing: -2px;
}
亲自试一试 »

空白

这个white-space属性指定如何处理元素内的空白。

此示例演示如何禁用元素内的文本换行:

示例

p {
  white-space: nowrap;
}
亲自试一试 »

CSS 文本间距属性

Property Description
letter-spacing Specifies the space between characters in a text
line-height Specifies the line height
text-indent Specifies the indentation of the first line in a text-block
white-space Specifies how to handle white-space inside an element
word-spacing Specifies the space between words in a text