background 可以设置背景颜色、背景图片、定位等。
background-color只能设置背景颜色。
background-color是background中的一个属性。
顺便提一下,color是字体的颜色,不是背景颜色。
body {
background: #00FF00 url(image.gif) no-repeat fixed top;
}
background可设的属性:
- background-color
- background-position
- background-size
- background-repeat
- background-origin
- background-clip
- background-attachment
- background-image
如
background:#ff0000 url('image.gif');
若不设置其中的某些值也是可以的 也是允许的。
(1)background-repeat 属性定义了图像的平铺模式:
值 | 描述 |
---|---|
repeat | 默认。背景图像将在垂直方向和水平方向重复。 |
repeat-x | 背景图像将在水平方向重复。 |
repeat-y | 背景图像将在垂直方向重复。 |
no-repeat | 背景图像将仅显示一次。 |
inherit | 规定应该从父元素继承 background-repeat 属性的设置。 |
(2)background-attachment 属性设置背景图像是否固定或者随着页面的其余部分滚动。
值 | 描述 |
---|---|
scroll | 默认。背景图像会随着页面其余部分的滚动而移动。 |
fixed | 当页面的其余部分滚动时,背景图像不会移动。 |
inherit | 规定应该从父元素继承 background-attachment 属性的设置。 |
(3)background-position 属性设置背景图像的起始位置。
属性值可以使用关键词、百分比、像素。
body {
background-position:center; /*关键词*/
background-position:30% 20%; /*百分比*/
background-position: 50px 100px; /*像素*/
}
网友评论