Forum Moderators: not2easy

Message Too Old, No Replies

Image rollover problem: Strange CSS/Javascript behavior?

Page looks wrong on first load, but reloading fixes it!

         

MichaelBluejay

2:27 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to replace my JavaScript image rollovers with CSS rollovers. You know, I have a transparent GIF in a 1-cell table, and I have the table set to change background colors on mouseover and mouseout:

<TABLE BGCOLOR="#006600" onmouseover="this.style.backgroundColor='red'" onmouseout="this.style.backgroundColor='#060'">
<TR>
<TD>
<P><IMG SRC="image.gif"></P>
</TD>
</TR>
</TABLE>

The problem is, if I load that page in IE6, the table is dark. If I mouseover then it lights up fine and if I mouseout then the proper color appears. It's just on the initial load that it doesn't work.

Now, here's the weirder part: if I don't mouseover, and leave the image all dark, and then click the Reload button in the browser, it appears correctly! That's so weird -- I've never seen a page that doesn't look right on the first load but looks just fine on a RE-load.

Here's a test page with nothing on it but the example:

<snip>(Ooops sorry no URLS's please see TOS [webmasterworld.com])

I found I could fix this by putting in a cludgy DHTML cross-browser JavaScript to set the background color, but my whole point in using CSS was to *avoid* JavaScript.

By the way, I don't have this problem on the Mac with either IE or Safari.

So who's the genius who can figure this one out? Thanks!

[edited by: SuzyUK at 8:57 am (utc) on May 8, 2004]
[edit reason] URL snipped [/edit]

Rambo Tribble

2:37 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was not able to duplicate the behaviour you report viewing the page with IE 6 on Win XP. The background color started as dark green on load and the image displayed properly.

MichaelBluejay

5:17 am on May 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm using Windows 98. Maybe the problem is specific to that OS? Anyone else with Windows 98 care to give it a whirl?

Noisehag

5:22 am on May 8, 2004 (gmt 0)

10+ Year Member



Working fine here. I'm using IE 6 on XP Pro.

MichaelBluejay

6:07 am on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I investigated this further and I get mixed results. Here's what I've discovered about the different ways to load the page:

1. Type in the url directly >> MAY OR MAY NOT DISPLAY CORRECTLY
2. Follow a link to the page >> MAY OR MAY NOT DISPLAY CORRECTLY
3. Click the Reload button >> ALWAYS APPEARS CORRECTLY
4. Click inside the address by and hit Return >> ALWAYS APPEARS WRONG

Can anyone replicate this? I'm surprised if nobody's run into this before. I'm not allowed to post a url here so here's all the code:

<HTML><BODY><CENTER>
<TABLE BGCOLOR=#006600 onmouseover="this.style.backgroundColor='red'"
onmouseout="this.style.backgroundColor='#060'">
<TR><TD><P><IMG SRC="image.gif"></P>
</TD></TR></TABLE>
</BODY></HTML>

Noisehag

9:24 am on May 9, 2004 (gmt 0)

10+ Year Member



Tried it out on the following:

Windows XP Pro - all current updates

IE 6.0
Netscape 7.01
Opera - Version7.23, Build 3227
Firefox 0.8
Mozilla 5.0

I tried by link, by typing and refresh. Works perfect. Sorry I don't have any testing setup for older stuff here at home...

Ooops, also tried clicking inside the address by and hitting return.

Sorry if I'm no help. =/

Noisehag

9:36 am on May 9, 2004 (gmt 0)

10+ Year Member



I might suggest going with the same call to color in every instance. Probably not it, but will narrow down the troubleshooting.

Green #006600
Red #FF0000

You never know...

Rambo Tribble

1:53 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another thing you might try is to make all your backgrounds CSS rules. Your initial table background color is in a element attribute. Depending on your!DOCTYPE declaration, you may need to put quotes around the BGCOLOR attribute value; now it has none, at least in your second example.

Have you tried validating your document at the W3C?

iamlost

8:36 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I ran it on win98se and ie5.0, 5.5 and 6, Netscape7.02, opera7.23, Build 3227, firebird0.7 and firefox0.8 and it worked fine.

Depending on your doctype your code may not validate and may not even display the image. However, in all instances the background displayed as expected.

MichaelBluejay

3:25 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks everyone for trying this on your systems, I appreciate it.

I guess since no one else can replicate it I'll just hope that only a very small minority of users will experience the problem. And maybe if they do, they'll wonder why the image looks screwy and they'll point to it, which will fix the problem. :)

I did try changing all the color references to the full six-digits, and putting them in quotes, but that didn't help. I'm not using any Doctype.

Thanks again for everyone's help on this. -MBJ-

Rambo Tribble

4:07 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not having a!DOCTYPE declaration as the first line of your HTML file throws IE into backwards-compatibility mode. That may (or may not) be the source of your problem.

pedoncio

8:40 pm on May 11, 2004 (gmt 0)

10+ Year Member



Win98 IE6 and NN7.1 with <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> works fine
bye

MichaelBluejay

8:54 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I tried each of these doctypes, one at a time, but none of the helped:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">