NOTE: This post has been replaced by a full-fledged tutorial – you can find that here. Please go there and don’t try what you see here; WordPress mangles my code snippets no matter how I try to get them displayed. The new tute is much better, I promise.
———————
This is a neat little trick that will allow you to create multiple clickable areas over any background image. This is easier, to me, than making image maps used to be.
Create a transparent box, absolutely positioned, that fits right over the top of the section of background image you want to make clickable. It’s easier to give this box a background-color while you’re getting it into position. The CSS looks like this:
/* This is the logo link clickable area */
#logo-zone {
position: absolute;
top: 18px;
left: 11px;
height: 21px;
width: 240px;
background-color: transparent;
}
Obviously you’ll change the ‘top’ and ‘left’ positions to line up with the top left corner of your background image’s clickable section, and adjust the ‘height’ and ‘width’ to fit.
Within the HTML, add an href link with the ID of your clickable box (WordPress won’t let me put this next link in here without screwing it up – remove the x from xhref):
<a id=”logo-zone” xhref=”yourlink.com” >
Pretty simple, and you can create multiple clickable areas wherever you need them on your page.


I don’t understand how it works. Could you be more idiot-proof with your explanations please?
Thanks. Tod.
When you use a background image on a div or other element in a cascading style sheet, the image is ‘glued’ to that element – it isn’t included as an image in your HTML file, so you can’t make it clickable by putting an anchor tag around it.
So instead you have to create a transparent box that you can position right over the top of the div with your background image, over the part that you want people to be able to click. You make the box in your CSS stylesheet, then give it an absolute position right on top of the div. Does that make sense?
If not, I’ll put together an example.
Hi, that’s exactly what I want to do – OK I have the transparent box positioned, but pasting in your code doesn’t work – ie the pointer doesn’t turn to a hand and nothing clickable.
I first tried this – but that didn’t work either.
Any ideas why pasting your html didn’t work?
Rob
Sorry the html after “I first tried this” has not come out – I’ll leave out the brackets – it was ‘a href=”http://www.robhealey.com.au/Contact”>
Rob – I think it was that I had used the wrong ID on the link – I’m trying to get this formatted but you can read it at least…
Change the ID to match the one in the CSS code snippet above the link snippet.
I’m using a background image in wordpress and positioning the transparent box is throwing all my other page elements out. I’m pasting the code a id=â€logo-zone†href=â€free-giftâ€. Any suggestions?
David, can you paste a link to your page so I can see? Did you give it position: absolute so it’s not included in the normal flow of the page?
Try this instead – http://www.position-relative.com/css_bg_image.php
That did the trick Debbie… your code above did not have /a> but the page you referred me to made it all clear. Thanks a lot
Thanks David… I’d been meaning to do this for a while now and your post finally made me. I’ll also put a note in this post about checking out the tutorial instead.
This does not work in Firefox….
Mike – you’re probably right. Did you try the tutorial that replaced this post?
http://www.position-relative.com/tutorials/tute1_css_bg_image.php
Hey, When I implement the above method with the border as 1px, it looks fine in Ie and FF but the clickable area is not the sameIE. I am guessing that its hiding behind the main image and the hand cursor is seen only in ~20px in the top and in the left side and rest has the border but not clickable. Is there anything I am missing here?thanks
pragan
pragan – were you using the tutorial that replaced this post, as mentioned in the first paragraph?
http://www.position-relative.com/tutorials/tute1_css_bg_image.php
I see no difference in the tute results in FF, IE7 or IE6. Try that.
pragan: set the “zoom” property to the absolutely positioned div. Like so:
#absolutely_pos_div {
zoom: 1;
}
This did the trick for me.
I put in and took out the div, got the yellow border in IE 7 but thats the only thing thats clickable, noting INSIDE the border is clickable. I dont want to do what others suggested, is make duplicate images of my buttons. HTML works ok but funny in different ways. but when you make a rectangle in html map, the whole rect is clickable, here it is not.
Having done this all my text moved to the left and I can’t figure out why!! anyone help?
Thanks for the quick tutorial. I used it on this site and it worked great. I think this is much easier than the old method of using image maps.
You’re very welcome.