liuli刘黎: 背景 (background) 属性定义元素的背景效果

2009年4月14日

背景 (background) 属性定义元素的背景效果

background
[编辑本段]background
   背景 (background) 属性定义元素的背景效果
  元素的背景区包括前景之下直到边框边界的所有空间。因此,内容框与内边距都是元素背景的一部分,且边框画在背景上。
  CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果;CSS 在这方面的能力远远在 HTML 之上。
  background 是用于在一个声明中设置所有背景属性的一个简写属性。
  格式: background: {属性值}
  继承性: NO
   可能的值:
  background-color
  background-image
  background-repeat
  background-attachment
  background-position
  注:可以在此声明中声明1到5个背景属性
  例:
  
[编辑本段]background属性详解及实例:
  background-color:{颜色值|transparent(默认值)} 属性设置元素的背景颜色。
  color 颜色值可以是颜色名称、rgb 值或者十六进制数。
  transparent 默认。背景颜色为透明。
  例:
   body
  {
  background-color: #00FF00
  }
  1.background-image:{URL(url)} 把图像设置为背景。
  url(URL) 指向图像的路径。
  none 默认。无背景图像。
  例:
   body
  {
  background-image: url(pic.jpg);
  }
  2.background-repeat:{repeat|no-repeat|repeat-X|repeat-Y} 设置背景图像是否及如何重复。
  repeat 默认。背景图像将在垂直方向和水平方向重复。
  repeat-x 背景图像将在水平方向重复。
  repeat-y 背景图像将在垂直方向重复。
  no-repeat 背景图像将仅显示一次。
  例:
  body
  {
  background-image: url(pic.jpg);
  background-repeat: no-repeat;
  }
  3.background-attachment:{fixed|scroll} 背景图像是否固定或者随着页面的其余部分滚动
  scroll 默认。背景图像会随着页面其余部分的滚动而移动。
  fixed 当页面的其余部分滚动时,背景图像不会移动。
   例:
  body
  {
  background-attachment: fixed;
  background-image: url(pic.jpg);
  }
   4.background-position:{位置值} 属性设置背景图像的起始位置。
  top left
  top center
  top right
  center left
  center center
  center right
  bottom left
  bottom center
  bottom right
  x% y%
  xpos ypos
  例:
   body
  {
  background-image: url(pic.jpg);
  background-position: top;
  }
  用javascript改变背景图片
  例:
   ....
  新建网页 1
  
  
  
  
  
  

标签:

1 条评论:

Blogger liuli 说...

1233
3
55

12:42 下午  

发表评论

订阅 博文评论 [Atom]

<< 主页