I'm working on a project that has a background image which needs to be repeated on the x-axis. There will be elements which have transparency overlaying the background image as well. Logically, I set the background attribute of the BODY element in my CSS:
- body {
-
background: #494949 url(http://example.com/myimge.png) repeat-x;
-
}
To my surprise, this worked in IE9, Firefox, Opera, and Safari, but not Chrome. Every other browser performed as expected, but Chrome wouldn't show the background image. So I tried changing the rule to html, body{}, now what was happening was, in Chrome, the background image showed up on the background of the page, but the body element wasn't getting the background image. Every other browser showed an instance of the background image on the HTML element, then another, slightly offset, on the BODY element. In addition, the transparent element wasn't showing through to the backgound image, since the body background had a color of #494949.
Finally, I tried separating the HTML and BODY rules:
- html {
-
background: #494949 url(http://example.com/myimage.png) repeat-x;
-
}
-
-
body {
-
background-color: transparent;
-
}
And that worked in all browsers.
My qustion is, is this normal behavior? I've always applied background images to the BODY element, have I been doing it wrong? Is this a good wa to accomplish what I'm going for? I don't want to hack together my CSS, I want to get this right.