- Jan 28, 2007
- 755
- 0
- 71
Just a quick question. If I were to put an image in HTML and I wanted to make it so that a portion of an image is a hyperlink to a certain page and another portion is a link to another page. How do you do this?
Originally posted by: QED
Imagemaps.
Normally to display an image, you would just use the <img> tag:
<img src="foo.gif">
To create linkable "hotspots" on this image, create an imagemap using the <map> tag, and fill it with shapes (such as rectangles) using the relative pixel coordinates of the image:
<map name="foomap">
<area shape="rect" coords="1,1,100,100" href="page1.htm">
<area shape="default" href="page2.htm">
</map>
In this case, we created a single rectange from (1,1) to (100,100) that, when clicked, will take you to page1.htm. Note that we also created a "default" shape, which specifies where to send every space not already defined-- in this case, to page2.htm.
To use the map, just include it in your original <img> tag:
<img src="foo.gif" usemap="#foomap" border=0>
(By default, a hyperlinked image will have an unnatural-looiking blue-border around it-- her we get rid of it by specifying "border=0" in the <img> tag).
Another way of doing it is to position an invisible <div> on top of an image and make it a hyper link.
