---
title: "CSS初级教程（四）- Text 文本"
author: "yacole"
date: "2007-01-03T12:37:02Z"
tags: []
slug: "css-text"
draft: false
lastmod: "2007-01-03T12:37:02Z"
id: 42857
url: "https://yacole.iteye.com/blog/42857"
---

一系列属性可以改变网页文字的大小和形状，概要如下：

## font-family

文字使用的字体，比如宋体，Times New Roman，Arial等等

这个属性必须详细制定，不能使用偏僻的字体，要使用安全字体（比如arial，verdana和times new roman和宋体），可以同时指定许多字体，只要使用逗号分开即可。这样的用意是，如果用户电脑里没有第一个字体浏览器可以使用后面指定的字体。这非常有用，因为不同的电脑拥有不同的字体。例子`font-size: arial,helvetica`，pc用户可以使用arial而苹果mac用户可以使用helvetica。

注意：如果字体的名称有许多单词组成，使用双引号组合，比如，`font-family: "Times New Romes"。`

## font-size

字体的大小，要小心使用。比如标题不会和段落一样，它要用大字体，你可以使用`h1h2`等等。

## font-weight

这个属性决定字体是否加粗。在实际运用中通常使用`font-weight: bold`或`font-weight: normal`。理论上还可以使用`bolder`,`lighter`,`100`,`200`, **`300`** , **`400`** , **`500`** , **`600`** , **`700`** , **`800`** or **`900`** ，但有些浏览器不认，仍坚持`bold`和`normal`。

## font-style

这个属性决定字体是否是斜体，可能是`font-style: italic`或`font-style: normal`。

## text-decoration

这个属性决定是文本否需要下划线。可以是：

- `text-decoration: overline`，加上划线
- `text-decoration: line-through`，加通过文本的线条。
- `text-decoration:underline`，这应该使用在链接上，因为用户习惯认为它代表链接。

## text-transform

改变文本的情况。

- `text-transform: capitalize` ，让每个字的第一个字母大写。
- `text-transform: uppercase` ，所有大写。
- `text-transform: lowercase`，所有小写。
- `text-transform: none;` ，这个属性不起作用。
  
  css 代码
  
  01. body {
  02. font-family: arial, helvetica, sans-serif;
  03. font-size: 0.8em;
  04. }
  05. h1 {
  06. font-size: 2em;
  07. }
  08. h2 {
  09. font-size: 1.5em;
  10. }
  11. a {
  12. text-decoration: none;
  13. }
  14. strong {
  15. font-style: italic;
  16. text-transform: uppercase;
  17. }

## Text spacing

`letter-spacing`和`word-spacing`属性的意思是字母和文字之间的间隔。值可以是长度或`normal`。

`line-height`属性设定元素的行高，比如一个段落，没有调准字体的大小。它可以是数字（字体大小的倍数），长度，百分比或`normal`。

`text-align`设定元素位置，`left`,`right`,`center`或`justify`。

`text-indent`属性缩进段落的首行。这在打印时经常设置，但网页里通常用不上。

css 代码

1. p {
2. letter-spacing: 0.5em;
3. word-spacing: 2em;
4. line-height: 1.5;
5. text-align: center;
6. }