Forum Moderators: not2easy

Message Too Old, No Replies

CSS "mock javascript rollover" problem

The buttons shift up and down in IE

         

Cher

4:10 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



Since I couldn't get Javascript rollovers to work in IE using the doctype of xhtml strict, I switched to using a CSS version based on the :hover attribute. It works just fine in Firefox and IE 7, but not so well in IE 6 (and I'm assuming older versions of IE as well).

CSS:


[2]
.invisible {display:none}
a#navimg1 {display:block; width:176px; height:40px; background-image:url(*my mouse up img*);
margin:0px 10px 20px 10px;
background-repeat:no-repeat; text-decoration:none; border:none;
background-color:#604028;
}
a#navimg1:hover {background-image:url(*my mouse over img*);
background-repeat:no-repeat;
text-decoration:none; border:none;
background-color:#604028;}
[/2]

HTML:


[2]
<a href="#" id="navimg1"><span class="invisible">Link 1</span></a>
<a href="#" id="navimg2"><span class="invisible">Link 2</span></a>
<a href="#" id="navimg3"><span class="invisible">Link 3</span></a>
(...and so on...)
[/2]

I have navimg1 through 7 using the same bit of code. If you hover over navimg1 and navimg2 in IE 6 they're fine, but once you mousover navimg3 the trouble begins. Navimg3 actually forces navimg2 to shift upwards 20px until you hover over navimg2 again, then it shifts itself back down. Navimg1 and 7 will keep their margins in place, but 2 through 6 will shift up and down like an accordion.

I have tried making them stick with position:relative on a :link and :visited (using IE conditionals to add an extra stylesheet) but so far nothing I try makes the images stick in place in IE 6.

Anyone have an idea?

[edited by: Cher at 4:14 pm (utc) on Feb. 1, 2007]

cmarshall

5:47 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I couldn't get it to happen. Here's the complete code I'm using (Note the DOCTYPE):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test</title>
<style type="text/css">
/* <![CDATA[ */
a#navimg1 {display:block; width:176px; height:40px; background-image:url(images/banner.gif);
margin:0px 10px 20px 10px;
background-repeat:no-repeat; text-decoration:none; border:none;
background-color:#604028;
}
a#navimg2 {display:block; width:176px; height:40px; background-image:url(images/banner.gif);
margin:0px 10px 20px 10px;
background-repeat:no-repeat; text-decoration:none; border:none;
background-color:#604028;
}
a#navimg3 {display:block; width:176px; height:40px; background-image:url(images/banner.gif);
margin:0px 10px 20px 10px;
background-repeat:no-repeat; text-decoration:none; border:none;
background-color:#604028;
}
a#navimg1:hover {background-image:url(images/banner_mouseover.gif);
background-repeat:no-repeat;
text-decoration:none; border:none;
background-color:#604028;}
a#navimg2:hover {background-image:url(images/banner_mouseover.gif);
background-repeat:no-repeat;
text-decoration:none; border:none;
background-color:#604028;}
a#navimg3:hover {background-image:url(images/banner_mouseover.gif);
background-repeat:no-repeat;
text-decoration:none; border:none;
background-color:#604028;}
/* ]]> */
</style></head>
<body>
<div>
<a href="#" id="navimg1"><span class="invisible">Link 1</span></a>
<a href="#" id="navimg2"><span class="invisible">Link 2</span></a>
<a href="#" id="navimg3"><span class="invisible">Link 3</span></a>
</div>
</body>
</html>

Cher

6:11 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



I seem to have left out some information; the navimgX are surrounded by a div that is 200px wide, which forces the images to lay vertically on the screen, not horizontally.

(normal - firefox and ie7)

+-----+
¦ img
+-----+

+-----+
¦ img
+-----+

(when mouseover'd in ie 6)

+-----+
¦ img
+-----+
+-----+
¦ img
+-----+

I copy/paste your strict doctype but it unfortunately didn't change anything.

If you start from the top at navimg1 and move your cursor down the navigation menu, all 7 image bunch together as though there were no bottom margins. If you reverse direction (start from 7 and mouse up to 1), the images reset and they all have their proper margins again.

It's kind of fun to run the mouse cursor up and down and watch the navigation area shrink and e-x-p-a-nd, but that's not what I'm intending to do :D

cmarshall

6:31 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It might be easiest if you just modify that file to a version that will reproduce the issue, so I can copy it into my local test file. That banner.gif file is quite a bit bigger than the one you specify. I can make one exactly that size.

Cher

7:45 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



All right, the problem seems to be with my default a:link, a:hover, and a:visited styles. I think IE 6 is reading them and adding in the styles, plus the special imgnavX:hover style. Once I commented out my default styles for the href links, the navigation stopped shifting up and down.


[2]
a:link, a:visited {font-family:verdana, helvetica, sans-serif;
color:#006633; background-color:#FFF7E5;
text-decoration:none; border-bottom:none;
padding:0px 2px 0px 2px;}
a:hover {font-family:verdana, helvetica, sans-serif;
border-bottom:1px dashed #666699;
text-decoration:none; padding:0px 2px 0px 2px;
color:#333366; background-color:#F0E8D8;}
[/2]

I tried just removing the padding: and leaving everything else in, but that just caused the accordian-effect to come back in IE. I had to completely remove that code to get the navimgX to stop shifting.

cmarshall

8:03 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like you have a lead.

Good hunting.

carguy84

9:29 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



why are you using xhtml strict?

cmarshall

10:40 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I always use XHTML 1.1. I was only using Strict because I wanted to relax a couple of things for a test.

If the browser will accept it, I send application/xhtml+xml

Makes the browser throw a fit if there is even a teeny thing wrong with the page.

Damn good discipline. I write pretty solid code, and I can usually fix issues in minutes, as the validator acts as a debugger for me.