本 章 C S S 的 主 要 作 用
在前面的章节介绍完了声明与应用的方法及 一些特性之後,从这章开始,便要正式进入CSS的指令介绍了!本章有两个介绍的主 题,第一个部份介绍的是颜色与背景性质的CSS,其主要的作用在于设定元素的前景 颜色、背景颜色与背景图形等样式设定的性质;而第二部份为您介绍的是用于控制摆放 元素位置的CSS的指令。
颜 色 背 景 的 C S S 指 令
color 设定前景颜色
支 持:IE3、IE4、NC4
适 用:所有元素
可能值: <color> 设定颜色,请参考第一章颜色使用的相关说明
预设值:视浏览器而定
继承性:有
一般范例:SPAN { color : BLUE }
同轴范例:<SPAN style="color:BLUE">
background-color 设定背景颜色
支 持:IE4、NC4
适 用:所有元素
可能值: <color> 设定颜色,请参考第一章颜色使用的相关说明
transparent 将父元素(颜色或图案)的背景透明化
预设值:transparent
继承性:无
一般范例:BODY { background-color : BLUE }
同轴范例:<BODY style="background-color:BLUE">
background-image 设定背景图形
支 持:IE4、NC4
适 用:所有元素
可能值: <url> 设定图档URL,请参考第一章URL表示的相关说明
none 不使用背景图案
预设值:transparent
继承性:无
一般范例:
BODY { background-image : URL("http://yourweb/path/file_name") }
同轴范例:
<BODY style="background-image:URL('http://yourweb/path/file_name')">
background-repeat 设定背景重复
支 持:IE4、NC4
适 用:所有元素
可能值: repeat 重复背景图形填满页面
repeat-x 水平方向重复背景图形
repeat-y 垂直方向重复背景图形
no-repeat 不重复显示背景图形
预设值:repeat
继承性:无
一般范例:BODY { background-repeat : repeat-x }
同轴范例:<BODY style="background-repeat: repeat-x">
background-attachment 设定背景附著
支 持:IE4、NC4
适 用:所有元素
可能值: scroll 背景图形随著卷轴卷动
fixed 背景图形随著卷轴卷动(浮水印)
预设值:scrool
继承性:无
一般范例:BODY { background-attachment : fixed }
同轴范例:<BODY style="background-attachment:fixed">
background-position 设定背景位置
支 持:IE4、NC4
适 用:区块元素
可能值: <percent> X% Y% 图形上X% Y%的点对准元素的X% Y%位置
<length> X Y 将图形左上角置于元素左上角水平 X垂直 Y之处
center 背景图形置于中央
left 背景图形对 左边
right 背景图形对 右边
top 背景图形对 顶部
bottom 背景图形对 底部
预设值:0% 0%
继承性:无
一般范例:BODY { background- position : 100% 50% }
同轴范例:<BODY style="background- position:100% 50%">
background 综合设定背景性质
支 持:IE3、IE4、NC4
适 用:所有元素
可能值: background-color 设定背景颜色
background-image 设定背景图形
background-repeat 设定背景重复
background-attachment 设定背景附著
background-position 设定背景位置
预设值:无
继承性:无
一般范例:
BODY { BLUE url(image/gif) repeat-x fixed center }
同轴范例:
<BODY style="BLUE url(image/gif) repeat-x fixed center">