参考文献: 《HTML, CSS, JavaScript 整合详解》 王津涛 编著,机械工业出版社
1. CSS背景属性,包括背景颜色、背景图片、背景图片重复等
背景属性 |
属性值 |
说明 |
CSS版本 |
兼容性 |
background |
background-color background-image background-repeat background-attachment background-position |
设置背景,复合属性 |
CSS1 |
IE 4 NS 6 F 1 |
background- attachment |
scroll fixed |
背景图片是否随网页内容滚动 |
CSS1 |
IE 4 NS 6 F 1 |
background- color |
color transparent |
背景颜色 |
CSS1 |
IE 4 NS 4 F 1 |
background- image |
url none |
背景图片 |
CSS1 |
IE 4 NS 6 F 1 |
background- position |
top left top center top right center left center center center right bottom left bottom center bottom right x-% y-% x-pos y-pos |
背景图片位置 |
CSS1 |
IE 4 NS 6 F 1 |
background- repeat |
repeat no-repeat repeat-x repeat-y |
图片是否重复或如何重复 |
CSS1 |
IE 4 NS 4 F 1 |
IE(Internet Explorer);N(Netscape);F(Firefox)
① background属性,设置网页背景,复合属性,语法格式为:
选择器 { background : background-color |background-image | background-repeat | background-attachment |background-position }
如:
② background- attachment属性,设置图片是否随网页内容滚动,语法格式为:
选择器 { background- attachment : scroll |fixed }
l scroll 图片随网页内容滚动
l fixed 图片在网页中固定不动
③ background- color属性,设置网页元素背景颜色,语法格式为:
选择器 { background- color: color | transparent}
l color 值可以为颜色名(如<hrcolor=red>)、十六位进制的颜色值(如<hr color=#FF000)、RGB混合模式(如<hr color=rgb(255,0,0))
l transparent 设置背景颜色为透明,该属性默认
④ background- image属性,设置网页元素背景图片,语法格式为:
选择器 { background- image : none | url }