日期:2013-10-27  浏览次数:21603 次

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

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: boldfont-weight: normal。理论上还可以使用bolder,lighter,100,200, 300, 400, 500, 600, 700, 800 or 900,但有些浏览器不认,仍坚持boldnormal

font-style

这个属性决定字体能否是斜体,可能是font-style: italicfont-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; ,这个属性不起作用。
  • body {font-family: arial, helvetica, sans-serif;font-size: 0.8em;}h1 {font-size: 2em;}h2 {font-size: 1.5em;}a {text-decoration: none;}strong {font-style: italic;text-transform: uppercase;}

    Text spacing

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

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

    text-align设定元素位置,left,right,centerjustify

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

    p {letter-spacing: 0.5em;word-spacing: 2em;line-height: 1.5;text-align: center;}