日期:2013-05-18  浏览次数:21176 次

核心提示:css模版教程,自定义模板必备之css属性知识。

该表只列出常用的CSS属性,及简要引见其次要功用,若要了解各所有属性和具体的用法,请参考相关书籍

属 性 名 称 属性功用及其取值 用 法 说 明 与 范 例
颜色与背景类
color 设置文字颜色
#rgb
#rrggbb
rgb(255,255,255)
rgb(100%,100%,100%)
H1{color:red}
H1{color:#f00}
H1{color:#ff0000}
H1{color:rgb(255,0,0)}
H1{color:rgb(100%,0%,0%)}
background-color 设置背景颜色,格式同上。 BODY{background-color:red}
BODY{background-color:#f00}
BODY{background-color:#ff0000}
BODY{background-color:rgb(255,0,0)}
BODY{background-color:rgb(100%,0%,0%)}
background-image 设置背景图片,
url(/imageURL)
body{backround-image:url(/back.jpg);}
background-repeat 设置背景图片能否反复陈列:
repeat-x(X轴反复陈列);
repeat-y(Y轴反复陈列);
No-repeat(不反复陈列)
BODY{background-repeat:repeat-x;}
BODY{background-repeat:No-repeat;}
background-attachment 设定背景图片能否卷动,默认为卷动。
scroll(卷动)
fixed(不卷动)
BODY{background-attachment:fixed;}
background-position 设定背景图片或背景颜色开始显示的位置,取值格式:
top,buttom,left,right,center(用关键字)
70px 10px(用长度值)
50% 30%(用百分比)
BODY{background-position:right top;}
BODY{background-position:50px 10px;}
BODY{background-position:20% 50%;}
background 定义背景综合属性,不要求顺序,各属性值以空格分开。 BODY{background:#ffcc00 url(/bg.jpg) fixed center}
字型类
font-family 设置字型属性,取值可以是任何字型名称,缺省为浏览器内定字型,可以设多个以逗号(,)分开,有空格的英文字型可用单引号或双引号括起来。 P{font-family:宋体,楷体,黑体,"Time New Rom";}
font-style 设定字型款式:Normal(正常),italic、objlique(斜体)  P{font-style:italic;}
font-variant 取值:Normal(默认),small-caps(如果是中文字型则将字型缩小显示,如果是英文则全部改为较小的大写) H3{font-variant:small-caps;}
font-weight 设定字体粗细,取值有:
Normal(默认),bold,lighter,border,100,200...900
由于浏览器支持程度不同,普通只用normal和bold两种属性。
P{font-weight:bold;}
font-size 设定字体的大小;
绝对大小:xx-small,x-small,small,mediumlarge,x-large,xx-large;
绝对大小:larger,smaller;
数字表示可用单位:磅(pt),像素(px),英寸(in),厘米(cm);
亦可用百分比表示。