Toggle navigation

CSS 文本

TEXT FORMATTING

文本格式化

This text is styled with some of the text formatting properties. The heading uses the text-align, text-transform, and color properties. The paragraph is indented, aligned, and the space between characters is specified. The underline is removed from this colored "Try it Yourself"link.

该文本使用某些文本格式属性来设置样式。标题使用 text-align、text-transform 和 color 属性。段落缩进、对齐,并指定了字符间距。然后从这个彩色的“试一试”链接中删除了下划线。

试一试

文本颜色

color属性用于设置文本的颜色。颜色由以下值指定:

  • 颜色名 - 比如 "red"
  • 十六进制值 - 比如 "#ff0000"
  • RGB 值 - 比如 "rgb(255,0,0)"

查看CSS 颜色值,以获取可能颜色值的完整列表。

页面的默认文本颜色是在 body 选择器中定义的。

实例

body {
  color: blue;
}

h1 {
  color: green;
}

试一试

提示:对于 W3C compliant CSS:如果您定义了 color属性,则还必须定义background-color属性。

文本颜色和背景色

在本例中,我们定义了background-color属性和color属性:

实例

body {
  background-color: lightgrey;
  color: blue;
}

h1 {
  background-color: black;
  color: white;
}

试一试