4.7 文档背景样式快捷定义background
属性值:background-color || background-image || background-repeat || background-attachment || background-position | 继承值
初始值:参见各属性的属性值
作用于:所有元素
是否继承:否
百分比值:仅对“background-position”有效
计算值:参见各属性的属性值
background属性允许用户一次定义所有有关背景的属性,因此称为文档背景样式快捷定义。浏览器在遇到background属性的时候,首先把所有和背景有关的属性全部视作各自的默认初始值,然后定义的属性再替换相应默认值。
示例4.12演示了一次定义所有背景的方法,效果如图4.21所示。
示例4.12
<html>
<head>
<title>CSS Demo</title>
<style>
body { background: black url(winnt.jpg) no-repeat fixed bottom right;
color: white;
font-family: Tahoma; }
</style>
</head>
<body>
<h3>Get help from other users</h3>
<p>Take advantage of tips, free downloads, and friendly experts who can answer your questions and make your time at the computer safer, easier, and more fun.
</body>
</html>

图4.21 利用bakcground属性一次定义所有背景属性
设计者用空格分隔所有属性值,浏览器识别background属性的时候,到分号为止。
|
注 意 |
||
|
|
快捷方式定义所有背景属性没有先后顺序。 |
|
恰如其分地运用background各类属性定义背景样式,就可以制作出视觉效果非常优秀的网站,如图4.22所示,微软的Windows Vista网站,运用CSS的background各项属性控制背景的样式。

图4.22 Windows Vista网站运用CSS的background属性定义背景样式






