Background-position not working when classname changed in IE7
I have an element which I am adding a class to.
the style is:
.bg{ background: url(/images/background.png) no-repe开发者_运维技巧at top center #000; }
When I add the class with javascript the background image show up, and the color show up, but the positioning does not.
This works fine in everything except IE
You have defined a vertical value (top), and one that doesn't exist (middle).
The vertical values are top
, center
and bottom
, while the horisontal are left
, center
and right
.
When using both, the first is the horisontal and the second is the vertical, so you got them backwards.
Use:
.bg{ background: #000 url(/images/background.png) no-repeat center top; }
You're not using the CSS background:
shorthand properly - you're missing the background-repeat
part. It should be something like this:
.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
精彩评论