
How do I create an image map for my Web page?I am trying to make a web page and am having trouble with the HTML. I want to make some links at different places on the picture on the front page. Could you help me with the code? Right now the whole picture is a link, but I would like to make the ENTER sign a link as well. If you could just point me in the right direction What you're talking about is what we Web folk call an image map, and they've been around in the Web world for years, albeit never too fabulously labeled or explained. The trick is that you need to do a fair bit of HTML footwork to get them to actually work properly... There are two parts to an image map (and in this explanation, I'm only going to talk about cilent-side image maps. Server side image maps are so crufty and old that I haven't seen them used on a site in years) the map itself, which identifies regions and assigns a target URL to each, and the additional attribute on the img tag that tells the Web browser that there's an associated map. To show you how this works, let's pick a graphical element that you might use on your own page. For fun, I'll pick the following image from the White House Web site: ![]() I include this image here with some basic HTML: <img src="http://www.whitehouse.gov/president/gallery/photoessay/images/fall-lg.jpg"
alt="whitehouse" height="267" width="400" /> To turn it into a clickable element, I wrap the img tag with an a href. That's still pretty rudimentary. Now, let's build an image map on top of the photo... You can build these coordinates by hand - the top left is 0,0 and you measure across, then down, so the center of this picture will be 400/2, 267/2, or 200,133 - but that's totally barmy, in my opinion. Instead, there are some nice shareware apps you can download to make things a lot easier, and every halfway decent Web page editor has a built-in image map utility too, some of which are wonderfully sophisticated. For Windows, you can try Imagemap Applet Builder, and for the Mac, check out YokMap. There are probably better free alternatives too, if anyone wants to recommend one... Whether you use the tool or not, an image map itself is a set of regions, coordinates that define those regions, and associated hypertext references. The three primary regions you can work with are RECT for rectangles, CIRCLE and POLYGON. For simplicity, most people work with rectangles, because you need only define the top left and bottom right points, so it's pretty easy. For demonstration purposes, let's take the image of the White House and make it so that clicking on the bottom left quarter takes you to the Democratic Party web site, clicking on the bottom right quarter takes you to the Republican National Committee site, and the top half of the image takes you to the White House site directly. Got it? Since we've already figured out that the center point is 200,133, and that the bottom right corner of the entire image is the exact dimensions of the image, or 400,267, that means that the top half can be represented as a rectangle with its top left coordinate of 0,0 and its bottom right coordinate as 400,133. The bottom left rectangle is 0,133 and 200,267 while the bottom right rectangle starts at 200,133 and ends at 400,267. I hope that makes sense! Now we're ready to turn these coordinates into an actual image map on a Web page! <map name="testmap">
<area shape="rect" coords="0,0,400,133" alt="top box" href="http://www.whitehouse.gov/" /> <area shape="rect" coords="0,133,200,267" alt="bottom left" href="http://www.democrats.org/" /> <area shape="rect" coords="200,133,400,267" alt="bottom right" href="http://www.rnc.org/" /> </map> Notice here that the image map gets a unique name - in this case testmap - and that each shape has all four coordinates specified in the coords attribute and that each has an href just like the a tag has. That's most of the work (and the hardest part, frankly) so now we just need to associate the image with the new image map. That's done by adding the new usemap attribute to the img, making sure to prepend a # to the name. So the actual image inclusion tag looks like this now: <img src="http://www.whitehouse.gov/president/gallery/photoessay/images/fall-lg.jpg"
alt="whitehouse" height="267" width="400" usemap="#testmap" border="0" /> Put it all together and here's a version of this image that has the three regions defined. Click on a different corner to see what happens! ![]() I hope that gets you moving in the right direction with image maps. If you want more information, may I suggest my popular book Creating Cool Web Sites as a good companion? In any case, good luck!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
HTML and CSS
(Article 4106)
Tagged: Previous: My Tablet PC takes forever to hibernate? Next: What's "shoplisting"? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. Thanks so much! This helped a lot! :D Posted by: Julie Mary at March 27, 2007 9:06 PMAn online tool to create image map can be found at: thank you so much Posted by: danny at October 30, 2007 9:59 PMAn other online tool WYSIWYG to create HTML image maps is http://www.kolchose.org/simon/ajaximagemapcreator/ Posted by: HTML image map at November 15, 2007 11:32 AMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 2000+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Industry News and Trade Shows Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|