Dreamweaver 教程-CSS背景属性(background)

【字号: 日期:2022-06-29浏览:25作者:雯心

但凡正规的网站在设计时都会注重网页背景的使用,一个好的网页背景与整体设计是息息相关的。下面我们就来讲讲一些常用的CSS背景属性。

1.背景颜色属性(background-color)

body { background-color:red ;}

2.背景图片(background-image)

body { background-image:url(http://www.rkxy.com.cn/images/logo.gif);}

如你所见,默认情况下背景图片会不断重复,直到布满整个网页,下面我们来看看如何用CSS控制背景图片的重复。

3.背景图片的重复设置(background-repeat)

(1)不重复

body { background-image:url(http://www.rkxy.com.cn/images/logo.gif); background-repeat:no-repeat; }

(2)水平方向重复

body { background-image:url(http://www.xiazaibaba.com/images/logo.gif); background-repeat:repeat-x;}

(3)垂直方向重复

body { background-image:url(http://www.rkxy.com.cn/images/logo.gif); background-repeat:repeat-y;}

4.背景图片位置(background-position)

body { background-image:url(http://www.rkxy.com.cn/images/logo.gif); background-position:center; background-repeat:no-repeat;}

5.将背景图片固定在某个位置(background-attachment)

该属性可以定义背景图片是否随着滚动条的滚动而改变位置。

body { background-image:url(http://www.rkxy.com.cn/images/logo.gif); background-attachment:fixed; background-repeat:no-repeat }
相关文章: