scriptygoddess

01 Oct, 2008

Repeating backgrounds and IE

Posted by: Jennifer In: CSS related

There's probably a really good reason for this (actually, wait. We're talking about IE. Nevermind) ;)

Just wanted to post a reminder to myself should I ever come across this weirdness again. I was working on a layout recently, and everything was working fine in Firefox, and everything was fine in IE except for one little nagging problem. A box that had a repeating background image in it sometimes showed up with the background in IE, and then sometimes not. Sometimes if I refreshed the page – suddenly the background image appeared. The line in my css calling for the background image looked like this:

#mybox {
background: url(images/my_background_tile.jpg) top left repeat-y;
}

Everything looks kosher – at least it SHOULD be. For some reason IE REALLY wanted a background color too! (even though it wouldn't be showing up because the image would be covering over it). Okay. Whatever. So this is what made the background image show up consistently:

#mybox {
background #fff url(images/my_background_tile.jpg) top left repeat-y;
}

IE was happy. And there was much rejoicing.
(*one quick note: this problem was specific to REPEATING background images. Background images set to no-repeat were not having problems)

Oh also – don't ever do this:

#mybox {
background: #fff url(images/my_background_tile.jpg) top repeat-y;
}

All kinds of weirdness happens then. If you're going to specify background coordinate locations (with either "top", "left", "5px", etc.) you have to specify both x and y locations. IE will hate you otherwise. And we don't want THAT! do we?

Related posts:

  1. Striping IMG tags from the_content in WordPress (and how to fudge page excerpts) Background: For a site I was working on, I was...
  2. Multi-Row Carousel and Image Loader with JQuery A recent project I've been working on involved a portfolio...

Related posts brought to you by Yet Another Related Posts Plugin.

5 Responses to "Repeating backgrounds and IE"

1 | lucas

October 18th, 2008 at 12:48 pm

Avatar

this is one time where IE did something right. you SHOULD put a background color that closely resembles the background image so that if that image isn't available the box should match up with the rest of your layout. also, if you're going to go through the trouble of positioning a background it makes total sense that you actually GIVE the position that you want the background to be in.

also, you forgot a ":" in your code… :)

2 | lucas

October 18th, 2008 at 3:25 pm

Avatar

Also, if you just wanted to do the background as an image you COULD use background-image: … background: is for setting ALL of the variables at once…

I know i probably sound like a super nerd, and please don't take this as me talking down to you. It really isn't meant like that EVER when I write. I'm just trying to explain why you're having problems. It is my way of helping the internet.

3 | Jennifer

October 18th, 2008 at 6:22 pm

Avatar

I guess the thing is that I was under the impression that background color should not need to be set – I don't believe it's required – and if not set – it should be transparent. I'd have to go back to the code I was working with but if I remember correctly, I think I even TRIED to set it to be transparent and it wouldn't work – so if you WANT it to be – you're kinda screwed because IE insists on it being a opaque solid color…

4 | lucas

October 18th, 2008 at 7:30 pm

Avatar

then you do
background: transparent url('path/to/file.png') top left repeat-y;

5 | Jennifer

October 18th, 2008 at 7:33 pm

Avatar

Again, I'll have to go back and check, but I'm pretty sure IE wasn't happy even with the transparent set as such. I'll keep you posted :)

Comment Form

Featured Sponsors


  • jerey: how do i rewrite this because it tried RewriteEngine on #Options +FollowSymlinks RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FIL
  • Jennifer: So I was testing this out to see if maybe something changed in the latest version - I had a test wordpress setup - and just dumped the mycomment funct
  • KDesign: Hi, thanks for the tutorial. I'm having problems though that I can't seem to find an answer to on the web. When I follow the example in the Codex h

About


Advertisements