spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / image_map / 1 current pageTo page 2To page 3
[next]

ASP 3.0/.NET Developer
Jupitermedia
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Computer Memory
GPS Devices
Cell Phones
Developer News
SaaS Tool Offers Custom Database Development
MicrosoftÂ’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear

How to Create an Image Map Using CSS

By Stu Nicholls.

Introduction

An image map is a way of defining multiple clickable link areas (hotspots) within one image. These 'hotspots' can then used for navigation or to display information about the image they cover.

In this article you will learn how to turn an ordinary definition list into an image map using nothing more than CSS, and what's more, it should work in all modern browsers, including Internet Explorer 5.5.

Here, you will learn one styling step at a time, fully explaining the reason for each style and showing the results of each step, so that you can see what to expect and implement it for yourself.

Method

The following steps will describe how to add images to the definition list and style the text so that it only shows when specific areas of the main image are selected.

Step 1

My example Definition List starts out as a list of Beatles names (they come from my era so it seems a suitable choice), their instruments and a piece of trivia information. The (x)html is written as follows.

<dl>
 <dt>
  The Beatles
 </dt>
 <dd>
  Paul McCartney - Bass Guitar and Vocals
  <br />
  <br />
  Paul McCartney's song, Yesterday, recently 
  voted the most popular song of the century 
  by a BBC poll, was initially composed without 
  lyrics. Paul used the working title 'scrambled eggs' 
  before coming up with the final words.
 </dd>
 <dd>
  Ringo Starr - Drums
  <br />
  <br />
  Dear Prudence was written by John and Paul 
  about Mia Farrow's sister, Prudence, when 
  she wouldn't come out and play with Mia and 
  the Beatles at a religious retreat in India.
 </dd>
 <dd>
  John Lennon - Guitar and Vocals
  <br />
  <br />
  In 1962, The Beatles won the Mersyside Newspaper's 
  biggest band in Liverpool contest principally 
  because they called in posing as different people 
  and voted for themselves numerous times.
 </dd>
 <dd>
  George Harrison - Lead Guitar and Vocals
  <br />
  <br />
  The Beatles' last public concert was held in 
  San Francisco's Candlestick Park on August 29, 1966.
 </dd>
</dl>

Because there are four Beatles I will need to define four 'hotspots,' but you can have as many as you like since the technique is the same.

In order that to style this list we need to add information that will enable us to target specific elements.

<dl id="imap">
 <dt>
  <a id="title" href="#nogo" title="The Beatles">
   The Beatles
  </a>
 </dt>
 <dd id="picp">
  <a id="paul" title="Paul McCartney" href="#nogo">
   <span>
    Paul McCartney - Bass Guitar and Vocals
    <br />
    <br />
    Paul McCartney's song, Yesterday, recently 
    voted the most popular song of the century 
    by a BBC poll, was initially composed without 
    lyrics. Paul used the working title 'scrambled eggs' 
    before coming up with the final words.
   </span>
  </a>
 </dd>
 <dd id="picr">
  <a id="ringo" title="Ringo Starr" href="#nogo">
   <span>
    Ringo Starr - Drums
    <br />
    <br />
    Dear Prudence was written by John and Paul
    about Mia Farrow's sister, Prudence, when 
    she wouldn't come out and play with Mia and 
    the Beatles at a religious retreat in India.
   </span>
  </a>
 </dd>
 <dd id="picj">
  <a id="john" title="John Lennon" href="#nogo">
   <span>
    John Lennon - Guitar and Vocals
    <br />
    <br />
    In 1962, The Beatles won the Mersyside Newspaper's 
    biggest band in Liverpool contest principally 
    because they called in posing as different people 
    and voted for themselves numerous times.
   </span>
  </a>
 </dd>
 <dd id="picg">
  <a id="george" title="George Harrison" href="#nogo">
   <span>
    George Harrison - Lead Guitar and Vocals
    <br />
    <br />
    The Beatles' last public concert was held in 
    San Francisco's Candlestick Park on August 29, 1966.
   </span>
  </a>
 </dd>
</dl>

I have added the following style information to the (x)html.

  1. id="imap" - to the dl tag so that we can define it's size to hold the main image.
  2. <a id="title" href="#nogo" title="The Beatles"> ... </a> - Because Internet Explorer will only accept the :hover pseudo class on links, we need to surround the dt text with this link and give it an id="title". I have used href="#nogo" instead of the usual href="#" so that anyone clicking the link will not jump to the top of the page (just make sure you do not have an anchor #nogo on your page). The title="The Beatles" has been added so that it will appear when the mouse is hovered over the main image.
  3. Each dd has been given a unique id so that we can style each one.
  4. Each dd text has been surrounded by a link for the same reason as with (2) above. These links have a unique id so that they can be individually targeted and a title as with (2) above.
  5. Each dd text has also been enclosed in a span so that we can manipulate the text separately from the link.

 


home / programming / image_map / 1 current pageTo page 2To page 3
[next]



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Software Engineering for Ajax · Perl Pragma Primer · Implement Drag and Drop in Your Web Apps: Part 2
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Policy-based Management in SQL Server 2008 – Part II · For Starters: Virtualization - Part 1 · USPS Rate-Change Tips for E-tailers

Created: March 27, 2003
Revised: March 29, 2005

URL: http://webreference.com/programming/image_map/1