Remote Rollover Demo | July 16, 2005

I’m just preparing my slides for Tuesdays training course and thought I’d post up a couple of my remote rollover demos.

The basic set-up is very simple. You take a regular unordered list and wrap an extra, non-semantic span around the link text.


<ul id="pic">
<li class="rich"><a href="#"><span>&raquo; Richard Rutter</span></a></li>
<li class="dan"><a href="#"><span>&raquo; Dan Cederholm</span></a></li>
<li class="dunstan"><a href="#"><span>&raquo; Dunstan Orchard</span></a></li>
</ul>

You then apply your background image to the list, and set it’s position to relative.


#pic {
  margin: 0;
  padding: 0;
  width: 640px;
  height: 480px;
  list-style: none;
  background: url(rich-dan-dunstan.jpg) no-repeat;
  position: relative;
}

In the first example I’m using the anchor elements to produce the rollover effect.


#pic a {
  display: block;
  width: 100px;
  height: 140px;
  text-decoration:none;
  color:#003399;
}

#pic a:hover {
  border: 1px solid #fff;
}

I’m then positioning the anchors using floats and margins


#pic a {
  float: left 
}

#pic .rich a {
  margin-left: 80px;
  margin-top: 40px;
}

#pic .dan a {
  margin-left: 90px;
  margin-top: 50px;
}

#pic .dunstan a {
  margin-left: 140px;
  margin-top: 60px;
}

and positioning the text links absolutely


#pic a span {
  position: absolute;
}

#pic .rich a span {
  bottom: -2em;
  left: 0;
}

#pic .dan a span {
  bottom: -3.2em;
  left: 0;
}

#pic .dunstan a span {
  bottom: -4.4em;
  left: 0;
}

Positioning the anchors using floats and margins works if the items you want to roll-over are all roughly in a line. However if they are not, you need to position them absolutely as well. You can’t position the anchors absolutely, so you need to add an extra, non-semantic span inside the anchors.


<ul id="pic">
<li class="rich"><a href="#"><span class="box"></span><span class="link">&raquo; Richard Rutter</span></a></li>
<li class="dan"><a href="#"><span class="box"></span><span class="link">&raquo; Dan Cederholm</span></a></li>
<li class="dunstan"><a href="#"><span class="box"></span><span class="link">&raquo; Dunstan Orchard</span></a></li>
</ul>

You can then absolutely position those elements as well.


#pic .rich a .box {
  top: 30px;
  left: 80px;
}

#pic .dan a .box {
  top: 60px;
  left: 270px;
}

#pic .dunstan a .box {
  top: 70px;
  left: 520px;
}

This is how the second example works. Both these examples are fairly rough. They haven’t been extensively tested so I wouldn’t be surprised if they break on IE. However I think they provide an interesting example of what can be achieved using some fairly basic CSS. Throw in some pure CSS rollovers and you’d have something akin to the way flickr displays comments on images.

Posted at July 16, 2005 11:50 AM

Comments on: Remote Rollover Demo

Jump to the comment form

 speach bubble Comment

Yea, it almost works in IE ;)

Posted by: Paul Goscicki at July 16, 2005 3:37 PM

 speach bubble Comment

Awesome tip! I’ve seen it around and never given it a try. Thanks!

Dan’s got the wrong url though - oops!

Posted by: Travis Schmeisser at July 16, 2005 3:41 PM

 speach bubble Comment

Whoa, that doesn’t work in IE at all. I wonder what it would take to fix it for all browsers?

Posted by: Clay Smith at July 16, 2005 3:49 PM

 speach bubble Comment

They’re all sortsa misplaced in IE.. sadly. :/

Also, your page layout gets broken in IE6 by the above code samples.

Want me to show you some samples of what all gets messed up in IE?

Posted by: Faruk Ateş at July 16, 2005 3:50 PM

 speach bubble Comment

Interesting. IE does break it I’m afraid.

If you were to attempt the same effect with javascript, do you think you would need less mark up?

Posted by: Neil Ford at July 16, 2005 3:56 PM

 speach bubble Comment

You’ll probably want to start by display: block’ing all those spans to get it to do what you’re expecting. Then I’d guess you’re looking at IE’s classic a:link/a:visited mismanagement; apply your positioning to both states and you’ve probably got it.

Posted by: Dave S. at July 16, 2005 4:27 PM

 speach bubble Comment

Andy,

Douglas’ photo gallery has a similar thing going on, yet his works fine in IE (6). Here’s his CSS in case you’re curious. :-)

Posted by: Faruk Ateş at July 16, 2005 4:28 PM

 speach bubble Comment

The first example was screwed in IE because of the double margin float bug. Adding display:inline seems to have fixed that. IE also seems to be basing the width of the span on the width of the anchor, instead of the new flow. Giving the span an explicit width seems to fix the text wrapping.

However I think the second example is going to be a bit more problematic to fix in IE.

Posted by: Andy Budd at July 16, 2005 4:59 PM

 speach bubble Comment

Nice…certainly good for an example of how flash/JS doesn’t always need to be used for every last “dynamic” effect. One thing, though…instead of just a:hover, why not a:hover, a:focus? That might help a bit for usability, aside from just the dotted gray outline that comes with tabbing.

Posted by: Ben Rogers at July 16, 2005 6:02 PM

 speach bubble Comment

The problem with example 2. in IE seems to be that neither of the rules targeting the spans using dynamic pseudo classes work.

#pic a:hover .box { border: 1px solid #fff; } #pic a:hover .link { color: #0066FF; }

So if you hover over the link text or the hot areas you get no visual feedback. This is weird as I’m doing a similar thing in example 1 and they worked correctly.

While trying to figure out why this was happening, I seem to have stumbled onto a fix. You can see it working in Example 2a.

Adding a border to all the anchor hover states seems to fix things in IE.

#pic a:hover { border: 1px solid transparent; }

I haven’t a clue what’s going on here, or why it would work, but it seems to do the trick. If anybody can throw any light on what’s happening here I’d really appreciate it, as my head hurts trying to imagine what IE thinks it’s playing at.

Posted by: Andy Budd at July 16, 2005 6:17 PM

 speach bubble Comment

Seems like it’s a known bug

Posted by: Andy Budd at July 16, 2005 6:53 PM

 speach bubble Comment

It’s the photo I like most ;)

Posted by: Jens Meiert at July 16, 2005 11:06 PM

 speach bubble Comment

Waiter, there’s behaviour in my presentation layer.

Posted by: Jeremy Keith at July 17, 2005 12:57 PM

 speach bubble Comment

Dunstan looks like Matt wotsit off A Question of Sport in that piccy.

Cool technique tho

Posted by: Rob Waring at July 19, 2005 2:45 PM

 speach bubble Comment

I looked at example 2a in IE 6/Win XP/SP 2. It definitley is working better than the other attempts, but I notice that when I hover over either a “head” in the image or even over the text link, the cursor does not switch to a hand as one would expect.

Also, in IE, I noticed that if I am mousing over top the “link” area, I am able to click a link that probably shouldn’t be there - in other words, I see that Richard Rutter is highlighted even thouh m cursor appears in the upper right-hand side of the image.

Man, I hate IE.

Anyway, an excellent implementation!

Posted by: Christian Ready at July 20, 2005 2:31 PM

 speach bubble Comment

Well, so far, both examples work well on my IE. Only thing is that when I move the cursor to the text link below the pix, both examples show the cursor as crosshair for selecting text instead of a hand, as stated by Christian above. On the pix, it did turn into a hand so that works fine. But still in the text link, the hover effect works fine, as are the links.

Posted by: Eric Quah at July 22, 2005 8:35 PM

 speach bubble Comment

This is really a good one. You can visit my site at the link below.

Posted by: Paul at July 28, 2005 10:25 AM

 speach bubble Comment

I have used a similar method months ago and it works in IE too.
http://www.stunicholls.myby.co.uk/menu/imap.html

Posted by: Stu at July 28, 2005 1:41 PM

 speach bubble Comment

Strange that it doesn’t work in Safari. I rarely see that happen.

Posted by: Andy Budd at September 2, 2005 4:43 PM

 speach bubble Comment

I didn’t know this effect was called Remote Rollovers. I have used something very similar on my site and always called ‘double action menu’.
You can see it in action at my web site
I used a dummy transparent 1×1 img for the remote rollover. I was inspired by Eric Meyers pure css popups
I wanted the images to ‘stay’ and be clickable. With some positioning I finally got it working.

AFAIK it works in most browsers.

Posted by: Rob Hofker at March 21, 2006 9:23 AM