📜  HTML |正文文本属性(1)

📅  最后修改于: 2023-12-03 15:15:39.927000             🧑  作者: Mango

HTML | 正文文本属性

HTML 的正文文本属性用于定义在网页正文中的文字部分的样式、排版和其他属性。本文将介绍一些常见的正文文本属性及其用法。

1. color

color 属性用于设置文字的颜色。颜色可以用预定义的颜色名称、颜色代码或 RGB 值来指定。例如:

<p style="color: red;">这是红色文字</p>
<p style="color: #007fff;">这是深蓝色文字</p>
<p style="color: rgb(255, 165, 0);">这是橙色文字</p>
2. font-size

font-size 属性用于设置文字的字号大小。可以使用绝对单位(如 px、pt 或 em)或相对单位(如 % 或 rem)来指定。例如:

<p style="font-size: 24px;">这是 24px 的文字</p>
<p style="font-size: 150%;">这是 150% 的文字</p>
3. font-family

font-family 属性用于设置文字的字体。可以使用预定义的字体名称或自定义字体名称来指定。例如:

<p style="font-family: 'Microsoft YaHei', sans-serif;">这是微软雅黑字体</p>
<p style="font-family: 'Helvetica Neue', Arial, sans-serif;">这是 Helvetica Neue 字体</p>
4. font-weight

font-weight 属性用于设置文字的粗细程度。可以使用预定义的关键字(如 bold 或 bolder)或数值(如 100、200、...、900)来指定。例如:

<p style="font-weight: bold;">这是加粗文字</p>
<p style="font-weight: 300;">这是粗细程度为 300 的文字</p>
5. font-style

font-style 属性用于设置文字的风格,如斜体、倾斜等。可以使用预定义的关键字(如 italic 或 oblique)来指定。例如:

<p style="font-style: italic;">这是斜体文字</p>
<p style="font-style: oblique;">这是倾斜文字</p>
6. text-align

text-align 属性用于设置文字的对齐方式,如左对齐、右对齐、居中对齐等。可以使用预定义的关键字(如 left、right 或 center)来指定。例如:

<p style="text-align: left;">这是左对齐文本</p>
<p style="text-align: right;">这是右对齐文本</p>
<p style="text-align: center;">这是居中对齐文本</p>
7. text-decoration

text-decoration 属性用于设置文字的装饰效果,如下划线、删除线等。可以使用预定义的关键字(如 underline、overline、line-through 或 blink)来指定。例如:

<p style="text-decoration: underline;">这是下划线文本</p>
<p style="text-decoration: line-through;">这是删除线文本</p>
8. line-height

line-height 属性用于设置文字的行高。可以使用绝对单位(如 px 或 pt)或相对单位(如 % 或 em)来指定。例如:

<p style="line-height: 1.5em;">这是行高为 1.5 倍字号的文本</p>
<p style="line-height: 30px;">这是行高为 30px 的文本</p>

以上是 HTML 正文文本属性的简单介绍,希望能对你有所帮助!