CSS的背景属性

CSS常用背景属性例如:

  1. background 设置或检索对象的背景特性
  2. background-attachment设置或检索背景图像是随对象内容滚动还是固定的
  3. background-color设置或检索对象的背景颜色
  4. background-image设置或检索对象的背景图像
  5. background-position设置或检索对象的背景图像位置
  6. background-repeat 设置或检索对象的背景图像是否及如何铺排

background 是最常用的属性,下面几个只是将background 的拆分,其本质上相同的。

body {background-color:red;}

将网页的背景颜色设置为红色。
同样

body{background:url(background.jpg) center top no-repeat;}

将background.jpg设置为背景图片,且居中,顶部对其,不重复。这是background属性的综合写法,语法结构上:
background:background-color background-image background-repeat backgroundattachment background-position;

body {background:red url(background.jpg) no-repeat fixed 40px 100px;}

上面的代码表示,网页的背景颜色是red,背景图片是background.jpg图片,背景图片不重复显示,背景图片不随内容滚动而动,背景图片距离网页最左面40px,距离网页最上面100px。当然这些也可以拆分开一个一个去设置。