天天看点

CSS background-color 、image 背景图片

默认值:transparent  透明

适用于:所有元素

继承性:无

动画性:是

计算值:指定值

<dl><dt></dt></dl>

设置或检索对象的背景颜色。

当同时定义了背景颜色和背景图像时,背景图像覆盖在背景颜色之上。

对应的脚本特性为backgroundColor。

背景图片 background-image

默认值:none

动画性:否

<dl></dl>

<dt>none: 无背景图。 </dt>

<dt></dt>

设置或检索对象的背景图像。

如果定义了多组背景图,且背景图之间有重叠,写在前面的将会盖在写在后面的图像之上。

对应的脚本特性为backgroundImage。

background-image : url(“http://static.criteo.net/flash/icon/nai_small.png”);  // 全URL路径

background-image : url(“/flash/icon/nai_small.png”);  // 根路径

background-image : url(“../nai_small.png”) ;  // 相对于css文件的路径

background-image : url(../nai_small.png) ;  //不写引号

background-image : url(‘../nai_small.png’) ; // 单引号

背景重复  background-repeat

&lt;repeat-style&gt; = repeat-x | repeat-y | [repeat | no-repeat | space | round]{1,2}

默认值:repeat

<dt>repeat-x:背景图像在横向上平铺 </dt>

<dt>repeat-y: 背景图像在纵向上平铺 </dt>

<dt>repeat: 背景图像在横向和纵向平铺 </dt>

<dt>no-repeat: 背景图像不平铺 </dt>

<dt>round: 背景图像自动缩放直到适应且填充满整个容器。(CSS3) </dt>

<dt>space: 背景图像以相同的间距平铺且填充满整个容器或某个方向。(CSS3)</dt>

允许提供2个参数,如果提供全部2个参数,第1个用于横向,第二个用于纵向。

如果只提供1个参数,则用于横向和纵向。特殊值repeat-x和repeat-y除外,因为repeat-x相当于repeat no-repeat,repeat-y相当于no-repeat repeat,即其实repeat-x和repeat-y等价于提供了2个参数值

对应的脚本特性为backgroundRepeat。

背景跟着内容滚动 background-attachment

&lt;attachment&gt; = fixed | scroll | local

默认值:scroll

<dt>fixed: 背景图像相对于窗体固定。 </dt>

<dt>scroll: 背景图像相对于元素固定,也就是说当元素内容滚动时背景图像不会跟着滚动,因为背景图像总是要跟着元素本身。但会随元素的祖先元素或窗体一起滚动。 </dt>

<dt>local: 背景图像相对于元素内容固定,也就是说当元素随元素滚动时背景图像也会跟着滚动,因为背景图像总是要跟着内容。(CSS3)</dt>

对应的脚本特性为backgroundAttachment。

开始做,坚持做,重复做

继续阅读