ITeye博客

CSS初级教程(四)- Text 文本

yacole · 2007-01-03 12:37 · CSS资料专区 · Markdown

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

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 代码

    1. body {
    2. font-family: arial, helvetica, sans-serif;
    3. font-size: 0.8em;
    4. }
    5. h1 {
    6. font-size: 2em;
    7. }
    8. h2 {
    9. 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. }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。