Skip navigation

Client Side Image Maps

How to add an image map to your page
Image maps aren't as bad as they seem, at least if you use a client side image map using HTML rather than a CGI program. I may add a section on using a CGI-driven image map later on, but for now, lets look at one that just uses HTML and an image!

To begin, let's look at a simple image map I created. If you click the left half of the image, you will be taken to a tables tutorial. If you click the right side, you'll get a tutorial on frames. Both the links are on one single image, so we just call it an image map. Try it out:

Image Map

So, how do we create one of these? First, you need to have an image you want to use. Just pick one you like, or make your own. Next, you need to know the width and height of the image you are using. If you are not sure, open the image in your image editing program. You should have some option that will tell you the width and height of the image.

Now you need to put the image on the page. To do this, you use the image tag, but with a new attribute: usemap.

<img src="eximap1.gif" width="200" height="40" border="0" alt="image map" usemap="#mymap" />

The usemap="#mymap" command tells the browser to use a map on the page, which is named "mymap". Notice how it uses the "#" symbol in front of the map name. Also notice that we defined the width and height of the image. This needs to be done so we can use coordinates later on when we define the map. Speaking of that, lets see how to define the map. For this map, we would place the following code somewhere on the page. I just put it right after the <img> tag to make it easy to find.

<map name="mymap" id="mymap">
<area shape="rect" coords="0,0,99,40" href="table1.htm" alt="Tables" />
<area shape="rect" coords="100,0,200,40" href="frame1.htm" alt="Frames" />
<area shape="default" href="http://www.pageresource.com" alt="Home" />
</map>

Now you can see where the usemap="#mymap" from the <img> tag comes from. The name of the map is "mymap". Now, let's look at what all of this means:

Now, you can use other shapes besides rectangles, but those are alot tougher to code by hand. I would suggest using a shareware image map creation program if you use other shapes in your map.

So, if you need a simple image map separated into rectangular sections, just do what we did above. You can have as many rectangular areas as you want, just add the extra area tags with coordiantes and urls. Sounds like fun, don't you think?

Well, that does it for now, let's go on to: Links: No Underline.

Tables Frames Home

 

Other Topics: ASP/PHP | DHTML | Java | Site Survey | Contact Us | Privacy Policy

Copyright © 1997-2009 The Web Design Resource. All rights reserved. Disclaimer.