作用:CSS 背景属性用于定义HTML元素的背景。
背景颜色
background-color 属性定义了元素的背景颜色。
栗子
页面的背景颜色使用在body的选择器中:
body {background-color:#b0c4de;}
CSS中,颜色值通常以以下方式定义:
- 十六进制 - 如:"#ff0000"
- RGB - 如:"rgb(255,0,0)"
- 颜色名称 - 如:"red"
背景图像
background-image 属性描述了元素的背景图像.
默认情况下,背景图像进行平铺重复显示,以覆盖整个元素实体.
页面背景图片设置实例:
body {background-image:url('paper.gif');}
背景图像 - 水平或垂直平铺
添加背景图片时,系统会重复图片已达到铺满的效果background-repeat:no-repeat;设置图片不重复
background-repeat:repeat-x;水平铺满
background-repeat:repeat-y;竖直铺满
当不重复且图片比界面小的时候,可以用下面的属性调整图片位置
background-position:right top;
背景- 简写属性
在以上实例中我们可以看到页面的背景颜色通过了很多的属性来控制。
为了简化这些属性的代码,我们可以将这些属性合并在同一个属性中.
背景颜色的简写属性为 "background":
body {background:#ffffff url('img_tree.png') no-repeat right top;}
背景属性:
background | 简写属性,作用是将背景属性设置在一个声明中。 |
background-attachment | 背景图像是否固定或者随着页面的其余部分滚动。 |
background-color | 设置元素的背景颜色。 |
background-image | 把图像设置为背景。 |
background-position | 设置背景图像的起始位置。 |
background-repeat | 设置背景图像是否及如何重复。 |