Forum Moderators: not2easy

Message Too Old, No Replies

Different background-image for IE6 and standard browsers?

Alpha PNG for real browsers, regular jpg for IE

         

Torniojaws

10:28 pm on Feb 19, 2008 (gmt 0)

10+ Year Member



Is there any way to have IE6 (and older within reason) display a different background-image than alpha PNG supporting browsers?

On my page I use an alpha PNG for the background, but naturally IE doesn't support it so I would just display a barebones JPG for IE users. However, IE seems to ignore the hack altogether. Here's what I'm trying to use:

Normal CSS:

.main2 {
background-image: url(main2.png);
background-repeat: repeat-y;
width: 700px;
height: auto;
padding-left: 190px;
}

And this hack is php included as the first thing in the head -tag, before the Title and Link tags:


<!-- protect other browsers from IE6's quirks -->
<!--[if IE]>
<style type="text/css">

body {
background-image: url(tausta.jpg);
}

.main2 {
background-image: url(iebg1.jpg);
background-color: black;
background-repeat: repeat-y;
width: 700px;
height: auto;
}

.main3 {
background-image: none;
background-repeat: repeat-y;
width: 700px;
height: 89px;
padding-left: 100px;
}

ul {
margin-left: 20px;
}

</style>
<![endif]-->

All other codes in that hack do work just fine, except for that background-image: url(iebg1.jpg); part. That's how it theoretically should work, but IE ignores the background completely and still tries to displays the alpha PNG with solid gray areas instead of transparency. That's why I want to make IE display a rough estimate JPG instead. Any ideas how to pull it off?

Thanks :)

[edited by: Torniojaws at 10:30 pm (utc) on Feb. 19, 2008]

ratman7

2:22 am on Feb 20, 2008 (gmt 0)

10+ Year Member



Possibly because you are specifying the background-color property after the background-image property.

Torniojaws

5:07 am on Feb 20, 2008 (gmt 0)

10+ Year Member



I tried it all three ways:
- without defining the background-color
- with background-color before background-image
- and background-color after background-image.

It didn't affect anything.

I also tried background-image: none; and even that didn't do anything. The only explanation is that IE simply ignores the background-image setting completely. I also tried having the IE-only CSS appear after loading the real CSS file, but the end-result is the same (except that the background-image in the Body tag is also ignored, which it doesn't ignore if the IE-only CSS is loaded before the real CSS): it still uses the PNG file.

[edited by: Torniojaws at 5:12 am (utc) on Feb. 20, 2008]

Torniojaws

5:23 am on Feb 22, 2008 (gmt 0)

10+ Year Member



According to this page, you should be able to feed a different CSS file to IE6. But it doesn't work. I tried telling IE to use a different CSS file, and then renamed the real CSS file and the end result should be that IE shows at least something style-wise and standard browsers display no CSS. But IE does not display any styles either:

[elated.com...]

Here's the parts in Head that matter:


<head>

<link href="layout/tyyli.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="img/favicon.ico"/>
<!-- protect other browsers from IE6's quirks -->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->

</head>

Edit:

Nevermind, IE was using a cached page and Ctrl + F5 didn't update the localhost cache. Always reload through re-entering the url -.-

[edited by: Torniojaws at 5:44 am (utc) on Feb. 22, 2008]

SuzyUK

8:46 am on Feb 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And this hack is php included as the first thing in the head -tag, before the Title and Link tags:

it shouldn't go first in the document it should go somewhere after the the main stylesheet is called, if it's before it's simply being overruled by the Cascade part of CSS.. perhaps put it just before </head> as it's in a template

[edited by: SuzyUK at 8:46 am (utc) on Feb. 22, 2008]

Torniojaws

11:18 am on Feb 22, 2008 (gmt 0)

10+ Year Member



Like I said, I tried it both ways. Before and after the main CSS link. But as per my edit on the last post, I got it working now.

SuzyUK

1:46 pm on Feb 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah OK glad you got it working :)