Be the first to write a review
Night of the Image Map
In this free tutorial, Stuart Robertson shows how to make an old-school image map for navigation, using CSS and XHTML:
"When the other designer sent me his concept for the site, I began to despair. He wanted the page to look like an old weathered book, with rough edges and grungy textures. The menu items were scattered about the page. How could I turn a well-structured document into something that looked so organic? I thought about image maps.
They were horribly outdated, but an image map would make things so much easier than chopping the background image into dozens of pieces and trying to use CSS to stitch it back together. It might have been crazy to think about using them again, but the old ways seemed to hold the answer. I decided to go back into the laboratory and see if I could .."
This article was originally published by A List Apart, and is reproduced by kind permission.
Guided by a master plan
In your CSS file add a background color for the document body and set the margin and padding to 0. We're going to be using absolute positioning, and this will help with our calculations.
body {
background-color: #000;
margin: 0;
padding: 0;
}
The background for our image map is applied to the outer div. You should set an appropriate height and width to make sure it is fully displayed.
#book {
background-image: url(/d/imagemap/images/»
bookpages.jpg);
height: 595px;
width: 750px;
}
Any styles that apply to the majority of the links can be defined together. More specific CSS rules can then be used to alter the attributes of individual links as required. Use absolute positioning and include a default height, width, and top position for all of the links. This is a good time to make sure the underlines are removed as well.
#menu a {
position: absolute;
height: 38px;
width: 88px;
top: 31px;
text-decoration: none;
}
To hide the text within links while retaining “clickability,” we use a CSS selector to identify the italicized text within the links contained in our nested div, and its visibility is set to hidden. It's important to include meaningful link text, even if it will be invisible to the majority of your users. This ensures that your site will be accessible for browsers that don't support CSS and users who are viewing it with an alternate stylesheet.
#menu a i { visibility: hidden; }
Once the general CSS is in place, we can position each link individually. To improve efficiency, links that share a common attribute such as left or top, can be defined together.
a#credits, a#indicia { top: 531px; }
a#home { left: 101px; }
a#preface { left: 221px; }
a#stories { left: 311px; }
a#gallery { left: 431px; }
a#forum { left: 526px; width: 61px; }
a#mementos { left: 591px; width: 98px; }
a#credits { left: 431px; }
a#indicia { left: 591px; }
When applied to the XHTML of our document, the menu links will now float independently above our background image. If we position them above areas of the image that look like links, we'll be all set. Placing your links correctly will usually take either careful calculation or a bit of trial and error.
CSS image maps can use the :hover pseudo element to define a separate style for each link's rollover state. This allows us to float new images above the background whenever the user moves their mouse over one of the invisible link areas.
a#home:hover { background-image: url(/d/imagemap/images/homeglow.jpg);
}
a#preface:hover { background-image: url(/d/imagemap/images/prefaceglow.jpg);
}
a#stories:hover { background-image: url(/d/imagemap/images/storiesglow.jpg);
}
a#gallery:hover { background-image: url(/d/imagemap/images/galleryglow.jpg);
}
a#forum:hover { background-image: url(/d/imagemap/images/forumglow.jpg);
}
a#mementos:hover { background-image: url(/d/imagemap/images/mementosglow.jpg);
}
a#credits:hover { background-image: url(/d/imagemap/images/creditsglow.jpg);
}
a#indicia:hover { background-image: url(/d/imagemap/images/indiciaglow.jpg);
}
A bug in Internet Explorer that causes the rollover images to refrain from disappearing as expected can be fixed by adding border: none to the :hover state of all the CSS image map links.
a#home:hover,
a#preface:hover,
a#stories:hover,
a#gallery:hover,
a#forum:hover,
a#mementos:hover,
a#credits:hover,
a#indicia:hover { border: none; }
You can see the final results of our CSS image map in Example 2.
Bruce Lawson
I'm the brand manager of glasshaus, a publishing company specialising in books for web professionals. We've a series for dreamweaver professionals - the dreamweaver pro series.