views:

210

answers:

4

Having issues getting specific background images to display in Firefox/Opera, all other browsers are playing ball (except obviously IE, for which I've had to compromise).

Currently, Opera won't allow multiple background images like so:

background-image: url('/images/h2_default_bg.png'), url('/images/dashed_bg_default.gif');
background-repeat: no-repeat, repeat-x;
background-position: top left, bottom left;

Also both Firefox and Opera are both being awkward when a background image is positioned in pixels:

background: url('/assets/images/dashed_bg.gif') bottom 2px repeat-x;

Are there any simple workarounds for either of these problems?

+3  A: 

Currently, Opera won't allow multiple background images like so:

Multiple background images like that are not possible in CSS2 / 2.1, which at the moment we still have to adhere to.

See this quirksmode page on which browsers currently support multiple backgrounds.

As for the other settings, background position definitely works across browsers, I'm not aware of any incompatibilies there. What exactly happens in Firefox and Opera?

Pekka
Multiple backgrounds are new in CSS3: http://www.css3.info/preview/multiple-backgrounds/ but it is not really supported yet (obviously).
Felix Kling
@Felix ah, I see. Thanks for the heads up.
Pekka
Works perfectly in Chrome, FF and Safari. IE didn't, but that wasn't a surprise and I had to create a workaround for a number of reasons anyway. I found that notation yesterday whilst browsing for answers, I hadn't seen it either but I was impressed that it worked in said browsers.
JFK1980
@JFK1980: As the link says, it is currently only support by WebKit based browsers (and Firefox also).
Felix Kling
@JFK1980 check out the quirksmode link in my updated answer.
Pekka
@Pekka: They are both just ignoring the "bottom 2px" for some reason and not displaying an image at all. If I change it to "bottom left", for example, then it works fine; as you'd expect.
JFK1980
@Pekka: Thanks for the link, had I actually been using my brain then I would have noticed it was only supported in Webkit browsers. It was the second issue that had me confused.
JFK1980
@JFK can you try explicit position values: `background-position-left` `background-position-top` writing it all together makes it awfully easy to mix something up.
Pekka
A: 

As you found out, multiple backgrounds works in all the modern browsers. It does work in Opera as of version 10.5. There is no information on whether IE9 will have it nor if/when IE will ever support it.

Rob
Yeah, but Opera 10.5 is still in beta and FF 3.5 is pretty solid, so it'll take time for people to migrate up from the older versions.
Piskvor
+4  A: 

Multiple backgrounds are only supported starting from Firefox 3.6 and Opera 10.5. Are those the versions you're testing in? Chrome and Safari already support them, which I presume you mean with "all other browsers ... except obviously IE"

As for your second problem, the spec says this about the background-position syntax:

If two values are given and at least one value is not a keyword, then the first value represents the horizontal position (or offset) and the second represents the vertical position (or offset).

So you've given them in the wrong order. Make it 2px bottom instead.

mercator
Ahh, I feel like such a fool now. Thank you, such a simple error.I don't think my Opera is that up-to-date, my bad, but at least I'll know it's not working in all versions now.
JFK1980
+1 good catch with the background image.
Pekka
A: 

Thanks for all the help guys, great to get such a warm reception on my first post.

JFK1980
Welcome to SO :) btw, if you're posting a comment (i.e. not a a question or answer), use the "add comment" link.
Piskvor
Oh right, will do. Thanks for the heads up.
JFK1980