📜  CSS-文字

📅  最后修改于: 2020-10-26 04:44:13             🧑  作者: Mango


本章教您如何使用CSS属性操作文本。您可以设置元素的以下文本属性-

  • color属性用于设置文本的颜色。

  • direction属性用于设置文本方向。

  • letter-spacing属性用于在组成一个单词的字母之间添加或减去空格。

  • 单词间隔属性用于在句子的单词之间添加或减去空格。

  • text-indent属性用于缩进段落的文本。

  • text-align属性用于对齐文档的文本。

  • 文本装饰属性用于下划线,上划线和删除线文本。

  • text-transform属性用于大写文本或将文本转换为大写或小写字母。

  • 空白属性用于控制文本的流向和格式。

  • text-shadow属性用于设置文本周围的文本阴影。

设置文字颜色

下面的示例演示如何设置文本颜色。可能的值可以是任何有效格式的任何颜色名称。

This text will be written in red.

它将产生以下结果-

设定文字方向

下面的示例演示如何设置文本的方向。可能的值为ltr或rtl

This text will be rendered from right to left

它将产生以下结果-

设置字符之间的间隔

下面的示例演示如何设置字符之间的字符。可能的值是normal或指定空格的数字。

This text is having space between letters.

它将产生以下结果-

设置单词之间的间隔

下面的示例演示如何设置单词之间的间距。可能的值是normal或指定空格的数字

This text is having space between words.

这将产生以下结果-

设置文字缩进

下面的示例演示如何缩进段落的第一行。可能的值为%或指定缩进空间的数字

This text will have first line indented by 1cm and this line will remain at its actual position this is done by CSS text-indent property.

它将产生以下结果-

设定文字对齐方式

下面的示例演示如何对齐文本。可能的值是left,right,center,justify

This will be right aligned.

This will be center aligned.

This will be left aligned.

这将产生以下结果-

装饰文字

下面的示例演示如何装饰文本。可能的值是none,下划线,上划线,直通,blink

This will be underlined

This will be striked through.

This will have a over line.

This text will have blinking effect

这将产生以下结果-

设置文字大小写

下面的示例演示如何设置文本的大小写。可能的值是none,大写,大写,小写

This will be capitalized

This will be in uppercase

This will be in lowercase

这将产生以下结果-

设置文本之间的空白

下面的示例演示如何处理元素内的空白。可能的值是normal,pre,nowrap

This text has a line break and the white-space pre setting tells the browser to honor it just like the HTML pre tag.

这将产生以下结果-

设置文字阴影

下面的示例演示如何在文本周围设置阴影。并非所有浏览器都支持此功能。

If your browser supports the CSS text-shadow property, this text will have a blue shadow.

它将产生以下结果-