在IE7中更改类名时,后台位置不起作用

时间:2010-11-10 01:03:18

标签: javascript internet-explorer-7

我有一个元素,我正在添加一个类。

风格是:

.bg{ background: url(/images/background.png) no-repeat top center #000; }

当我用javascript添加类时,背景图像显示,颜色显示,但定位没有。

除IE之外的所有内容都可以正常使用

2 个答案:

答案 0 :(得分:1)

您没有正确使用CSS background:简写 - 您错过了background-repeat部分。它应该是这样的:

.bg {
    background: #000000 url(/images/background.png) no-repeat scroll center top;
}          /*   ^       ^                           ^           ^     ^
                color   image                       repeat attachment position */

http://www.w3schools.com/css/css_background.asp

答案 1 :(得分:1)

您已定义了一个垂直值(顶部),另一个不存在(中间)。

垂直值为topcenterbottom,而水平为leftcenterright

当使用两者时,第一个是水平的,第二个是垂直的,所以你让它们向后。

使用:

.bg{ background: #000 url(/images/background.png) no-repeat center top; }