3.3 背景属性background
作者:蛛蛛虎 日期:2008-07-02
3.3 背景属性background
背景属性主要用来定义选择符对象的背景颜色、背景图片及其显示方式的。常用的属性如下。
1)背景颜色属性(background-color)
这个属性为HTML元素设定背景颜色,相当于HTML中bgcolor属性。例如:
body {background-color:#99FF00;}
|
上面的代码表示body元素的背景颜色是翠绿色的。
2)背景图片属性(background-image)
这个属性为HTML元素设定背景图片,相当于HTML中background属性。例如:
<body style="background-image:url(../images/css_tutorials/background.jpg)"> |
上面的代码为body元素设定了一个背景图片。
3)背景重复属性(background-repeat)
这个属性和background-image属性连在一起使用,决定背景图片是否重复。如果只设置background-image属性,没设置background-repeat属性,在默认状态下,图片既横向重复,又竖向重复。可选值有:
repeat-x,背景图片横向重复。
repeat-y,背景图片竖向重复。
no-repeat,背景图片不重复。
例如:
body {background-image:url(../images/css_tutorials/background.jpg);
|
上面的代码表示图片竖向重复。
4)背景附着属性(background-attachment)
这个属性和background-image属性连在一起使用,决定图片是跟随内容滚动还是固定不动。这个属性有两个值,一个是scroll,另一个是fixed。默认值是scroll。例如:
body {background-image:url(../images/css_tutorials/background.jpg);
|
上面的代码表示图片固定不动,不随内容滚动而动。
5)背景位置属性(background-position)
这个属性和background-image属性连在一起使用,决定了背景图片的最初位置。例如:
body {background-image:url(../images/css_tutorials/background.jpg);
|
上面的代码表示背景图片的初始位置距离网页最左面20px,距离网页最上面60px。
6)背景属性(background)
这个属性是设置背景相关属性的一种快捷的综合写法,包括background-color、background- image、background-repeat、background-attachment、background-position。例如:
body {background:#99FF00 url(../images/css_tutorials/background.jpg)
|
上面的代码表示,网页的背景颜色是翠绿色,背景图片是background.jpg图片,背景图片不重复显示,背景图片不随内容滚动而动,背景图片距离网页最左面40px,距离网页最上面100px。
| 上一节 回书目录 下一节 |


上一篇:
下一篇:
文章来自:
Tags:
相关日志: