所有CSS-Text属性

属性 描述
color 设置文本颜色
direction 设置文本方向。
letter-spacing 设置字符间距
line-height 设置行高
text-align 对齐元素中的文本
text-decoration 向文本添加修饰
text-indent 缩进元素中文本的首行
text-shadow 设置文本阴影
text-transform 控制元素中的字母
unicode-bidi 设置或返回文本是否被重写
vertical-align 设置元素的垂直对齐
white-space 设置元素中空白的处理方式
word-spacing 设置字间距

文本颜色[color]

  • 设置字体颜色就color,不要加一个text-color
    1
    2
    3
    body {color:red;}
    h1 {color:#00ff00;}
    h2 {color:rgb(255,0,0);}
    效果如下:

W3C标准的CSS:如果定义了颜色属性,还必须定义背景色属性。当然,知道的人不多罢了。

对齐方式[text-align]

  • 设置文本的水平对齐方式。
    文本可居中或对齐到左或右,两端对齐.
    text-align设置为justify,每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸)
    1
    2
    3
    h1 {text-align:center;}
    p.date {text-align:right;}
    p.main {text-align:justify;}
    效果如下:

文本修饰[text-decoration]

  • 用来设置或删除文本的装饰。text-decoration属性主要是用来删除链接的下划线:
    1
    a {text-decoration:none;}
  • 也可以这样装饰文字:
    1
    2
    3
    h1 {text-decoration:overline;}
    h2 {text-decoration:line-through;}
    h3 {text-decoration:underline;}
    效果如下:

文本转换

  • 文本转换属性是用来指定在一个文本中的大写和小写字母。可用于所有字句变成大写或小写字母,或每个单词的首字母大写。
1
2
3
p.uppercase {text-transform:uppercase;}
p.lowercase {text-transform:lowercase;}
p.capitalize {text-transform:capitalize;}

效果如下: