h1 { text-align: center; } h2 { text-align: left; } h3 { text-align: right; } ------------------------当 text-align 属性设置为 "justify" 后,将拉伸每一行,以使每一行具有相等的宽度,并且左右边距是直的(就像在杂志和报纸中):-------------------------------- --------------------------------文本方向-------------------------------- direction 和 unicode-bidi 属性可用于更改元素的文本方向: 实例 p { direction: rtl; unicode-bidi: bidi-override; } ----------------------------------------------------------------垂直对齐---------------------------------------------------------------- vertical-align 属性设置元素的垂直对齐方式。 本例演示如何设置文本中图像的垂直对齐方式: 实例 img.top { vertical-align: top; } img.middle { vertical-align: middle; } img.bottom { vertical-align: bottom; }

一幅 W3School 默认对齐方式的图像。


一幅 W3School 上对齐的图像。


一幅 W3School 居中对齐的图像。


一幅 W3School 下对齐的图像。

----------------------------------------------------------------文字装饰---------------------------------------------------------------- text-decoration 属性用于设置或删除文本装饰。 text-decoration: none; 通常用于从链接上删除下划线: h1 { text-decoration: overline;上 } h2 { text-decoration: line-through;中 } h3 { text-decoration: underline;下 }

This is heading 1

This is heading 2

This is heading 3

下 ----------------------------------------------------------------文本转换---------------------------------------------------------------- text-transform 属性用于指定文本中的大写和小写字母。 它可用于将所有内容转换为大写或小写字母,或将每个单词的首字母大写: p.uppercase { text-transform: uppercase;大写 } p.lowercase { text-transform: lowercase;小写 } p.capitalize { text-transform: capitalize;将每个单词的首字母大写 }

This is some text.

This is some text.

This is some text.

----------------------------------------------------------------文字缩进---------------------------------------------------------------- text-indent 属性用于指定文本第一行的缩进: 实例 p { text-indent: 50px; } 字母间距 letter-spacing 属性用于指定文本中字符之间的间距。 下例演示如何增加或减少字符之间的间距: 实例 h1 { letter-spacing: 3px; } h2 { letter-spacing: -3px; } 行高 line-height 属性用于指定行之间的间距: 实例 p.small { line-height: 0.8; } p.big { line-height: 1.8; } 字间距 word-spacing 属性用于指定文本中单词之间的间距。 下例演示如何增加或减少单词之间的间距: 实例 h1 { word-spacing: 10px; } h2 { word-spacing: -5px; } white-space 属性指定元素内部空白的处理方式。 此例演示如何禁用元素内的文本换行: 实例 p { white-space: nowrap; } text-shadow 属性为文本添加阴影。 实例 h1 { text-shadow: 2px 2px; } 然后,向阴影添加模糊效果(5px): h1 { text-shadow: 2px 2px 5px red; } 所有 CSS 文本属性 属性 描述 color 设置文本颜色。 direction 指定文本的方向 / 书写方向。 letter-spacing 设置字符间距。 line-height 设置行高。 text-align 指定文本的水平对齐方式。 text-decoration 指定添加到文本的装饰效果。 text-indent 指定文本块中首行的缩进。 text-shadow 指定添加到文本的阴影效果。 text-transform 控制文本的大小写。 text-overflow 指定应如何向用户示意未显示的溢出内容。 unicode-bidi 与 direction 属性一起使用,设置或返回是否应重写文本来支持同一文档中的多种语言。 vertical-align 指定文本的垂直对齐方式。 white-space 指定如何处理元素内的空白。 word-spacing 设置单词间距。