Kimler Sidebar Menu

Kimler Adventure Pages: Journal Entries

search cloudRandom Searches
random top 40

Weather Forecast for Yellow Point, B.C.

Today

N/A

N/A

N/A° C

POP - 70%

Tonight

Showers

Showers

9° C

POP - 70%

Tomorrow

Showers

Showers

14° C 9° C

POP - 70%

Thu 15-May

Partly Cloudy

Partly Cloudy

20° C 12° C

POP - 10%

Fri 16-May

Mostly Sunny

Mostly Sunny

24° C 13° C

POP - 20%

Sat 17-May

Mostly Sunny

Mostly Sunny

23° C 12° C

POP - 20%

Weather data provided by weather.com®

z-index on a:hover elements

Filed in:CSS
The Web

z-index on a:hover elements

September 11th, 2005  · stk

An(other) IE6 Shortcoming

UPDATE 10-May-2006: Thanks to Stu Nicholls & ¥åßßå, I have found an effective work-a-round for this IE z-index issue. (See the solution).

I developed the second, more advanced version of the pure-CSS Photo Zoom (PZ2) in mid June. Besides our long summer vacation, one of the reasons I haven't yet published a 'production version', has revolved around a couple of problems with MSIE. I've found a work-a-round for one, but the other issue - a Z-index change on hover - remains.

I believe that the problem is "unsolvable". The work-a-round is not ideal, as it adds unnecessary complexity and limits PZ2s application. I am not happy. >:(

I blame it all on Microsoft's poor support for CSS standards.

At issue: IE's inability to support a z-index value change for a hovered element.

For an explanation and demonstration, as well as an IE "fix", read on...

- -

A Explanation and Demonstration

The main advantage of PZ2, over the original, is that in PZ2 the zoomed image overlays the text, instead of shifting the text to make room for the zoomed image. This is demonstrated below. (Note: There are some caption styling differences between the two, which can be changed, in the CSS file, to be alike.)

The image on the left zooms using the original and the image on the right is zoomed using PZ2. With the original, the larger the size difference between the thumbnail and zoomed image, the more the text has to shift, which can be jarring & disorienting. (Of course, as my wife has pointed out, using the original zoom, one can still READ the text, while looking at the picture ... which can't be done using PZ2 ... perhaps, the older version is preferable in some applications?).

Using PZ2 with a single photo, there generally isn't a z-index problem. It's not until multiple photos are used, which overlap each other upon zoom, that the z-index problem using PZ2 becomes obvious.

Z-index is a CSS property that places elements in front (or behind) one another. It's a seldom used and often confusing property, mainly because it only affects positioned elements (meaning that the element MUST be either relatively or absolutely positioned, or z-index won't do a thing).

If this is a property that you've struggled with (I know I have), a key thing to remember is that an element can be easily positioned with a "position:relative" declaration, without affecting its placement on the screen. So, when using z-index, make certain that the element is positioned and if it's not - apply a "position:relative;" declaration.

Look at the multiple photos below. No z-index consideration has been made. When you zoom the left-most photo, you see that it doesn't overlay the ones next to it. This is because each element placed on an XHTML page has an inherent z-index that is higher than what precedes it - meaning that each successive element is "placed on top" of the element before it. Make sense?

 

Normally, elements don't zoom on hover, so this inherent z-index assignment isn't a problem. However, it looks pretty crappy with PZ2 and needs to be dealt with.

Easy. Assign a low z-index value to all un zoomed PZ2 photos on a page. Then, assign a high z-index value to the PZ2 photo that a mouse is hovering over (only one photo can be zoomed at any given time).

Of course, FireFox (a more modern browser), which follows the CSS standard more closely than MSIE, doesn't have a problem with this declaration. MSIE, however, can't make heads or tails of the declaration and so - ignores it. Look at the photos below. If you're viewing in Firefox - no problem - things look good. If you're viewing in MSIE - problem - things look just like they did above ... YUCK!

 

The IE "FIX"

After banging my head against the wall and trying a bunch of different things, some of which involved some very loud cursing, I came to the conclusion that I'd have to play games with IE and that PZ2 would suffer slightly, as a result.

The fix involved numbering each successive PZ2 photo on a page and REVERSING the inherent z-index values, by assigning a lower z-index value to each successive PZ2 photo.

The results can be seen below. Now the zoomed images look fine in BOTH Firefox and IE.

 

The solution works, as long as a zoomed photo doesn't overlay any previous photos. It also 'breaks' if a zoomed photo, at the end of one entry, overlays the first zoomed photo of the NEXT entry. (So, you see, there are limitations with this 'fix' ... which is why I still direct my ire at Microsoft, for not supporting the CSS standards). Grrrr. :>

The Future

With the beta 1 release of IE7 (July 27, 2005) there is much hope that this version will make up for many of the CSS shortcomings of IE6. As you can read on the IEBlog, there are a bunch of standards support issues that will be addressed in IE7, but unfortunately, many will also remain.

I'm afraid that changing the Z-Index on a hovered element, will be around for some time to come.

Again .... grrrr. :>

Regarding a production release of PZ2 - I'm still working with the code, stabilizing, pruning and adding small features. I've been using it on this blog for the past few entries and the code has been improved markedly. It's now just down to the final testing and should be out shortly. Stay tuned!

10-May-2006 Update

I noticed that Stu Nicholl's Photo Gallery Mk.3 doesn't have a z-index overlay problem. Upon closer examination, I understand why. It's not something that I had ever considered and it shows the power of collaboration on such issues.

Normally, when positioning elements absolutely, I place them INSIDE a relatively positioned element. Doing so resets the origin point to the relatively positioned parent and then one can position the absolute element, within the parent, by using the [ top | left | right | bottom ] properties. However, if one positions an element absolutely, and doesn't use any of the aforementioned positioning properties, it remains fixed at it's original location on the screen (though taken out of the document flow). By using margining to position the element, it's done from THAT location (not the parent or page origin) AND ... the key part ... there is no IE z-index problem in assigning the hovered element a large z-index value.

Have a look at the example below, to see what I mean.

 

Note: the middle image in this example is margined to open closer to the center of the image, which means that it will covers BOTH the left and right thumbs. This configuration is NOT possible, using the earlier "fix" (as it only reverses the natural z-index order) rather than assigning a "highest" z-index value to the hovered image.

**Also: the image elements cannot be placed inside a relatively positioned parent, otherwise the IE z-index issue returns.

Hope this helps! It did me, as this technique is now employed in the (best yet) 3rd version of Photo-caption Zoom.

(Permalink)
Views: 27469 views
11 Comments · Email Story
Updated: 14-Mar-2007
Web View Count: 27469 viewsLast Web Update: 14-Mar-2007

Your Two Sense:

XHTML tags allowed. URLs & such will be converted to links.


Subscribe to Comments

Auto convert line breaks to <br />

1.flag Lewis Comment
10/19/06
Giving it a border appears to work too. Even a 0px border will work.
2.flag stk Comment
10/24/06
What's "it"? Most of the image tests above HAVE a border (on the image) and it still fails in IE.

If you've got a link to an example, I'm all eyes, but as you can see, having a border on the image does nothing to solve the problem.
3.flag Jonathan Haun Comment
12/26/06
I found that if you use the hack:

html*#whatever { z-index:1 } for IE, this works on some things. I didn't try it on this, but it's helped me out with z-index stuff in the past.
4.flag stk Comment
03/14/07
Jonathan,

Thanks for writing.

That hack selects ALL descendants of the HTML element in IE7 and lower, and it uses invalid CSS to do so. (i.e., your CSS won't validate, as you'll get a PARSE ERROR).

Regardless, flattening every element in IE won't fix the IE BUG, which is about SWITCHING z-index for any hovered element (i.e., from a { z-index:1 } to a:hover { z-index:2 }).

Cheers,

-stk
5.flag Gordie Comment
05/28/07
I'm trying to make a 'stack' of images change, depending on where the mouse is over the area the image is displayed on.
I have a rough version of this using image maps at http://www.a2zracergear.com/rows.html
However, the complete functinality works only in firefox.
For example, if you roll over 'Luggage' a new image shows up.

I can't seem to do more than a simple rollover in css, can you help?
6.flag stk Comment
05/28/07
Gordie,

You might want to have a look at this post.

Yes, I'm sure I can help. Just contact me and I'll help you get what you want.

Cheers,
-stk
7.flag Paul Comment
06/06/07
Thanks a million! This hack solved a very pesky problem I was having where we were attaching drop down menus to images. In IE, menus would appear under the next image, but your hack fixed the issue. I cant tell you how much stress this issue caused me. Thanks for relieving it!
8.flag stk Comment
06/06/07
Paul,

You're welcome and glad it helped. LOL, if only the thanks were a "million" dollars, eh?

Nice: A link-back to randsco.com

Nicer: A PayPal donation to skimler·at·yahoo·com

Cheers,
-stk
9.flag Gerwin Comment
05/09/08
Hey, thanks heaps for the fix. It worked perfectly for what I'm doing. In the CMS I'm building, the image manager displays the images in-window and when you click on an image, it brings up a menu with editing options. As you can imagine, the menu in IE went under the other icons. I did what you recomended and it worked great!


Here's some screen shots!

Thanks Mate.

 

10.flag stk Comment
05/10/08
Gerwin - Glad to hear that the technique helped. It's a frustrating problem and an intriquing solution, eh?

Thanks for commenting and posting the results. I'll embed the images, so you no longer have to worry about hosting them.

Cheers - stk
11.flag Gerwin Comment
05/10/08
Absolutely. It's definitely a frustrating problem and it's often one that can't go ignored and indeed a very good solution.

Cool @ hosting - that'd be great.

Thanks again,