HTML CSS IMAGES LINKS | |||||
HTML → Creating an Image Map Image maps are a combination of HTML code applied to an image, enabling a single image to link to multiple pages based on the position of the cursor over the image. As we have already learned, a single image can serve as a link simply by placing the image tag in between the opening and closing portions of the link tag as in the following example: <a href="http://www.yahoo.com"> <img src="../../../images/yahoo.gif" width="243" height="48" alt="yahoo" border="0"> </a>
But what if we wanted a single image to direct the user to multiple destinations?
Before we continue, in Photoshop prepare an image that is 400 pixels wide and 40 pixels high. Name the image - navigation
The image is now ready for the code of the image map. Create the following html pages:
place a heading in each of the pages to reflect their content . Using the img tag, code the image so it appears at the top of each of the pages.
Before we add to our code, we need to return one more time to photoshop. In order to code an image map we most first gather the different coordinates of the separate regions within our image. Any region on the image can be defined by its upper-left and lower-right corners. Each of the corners coordinate will be determined by the value of its x and y coordinates. Wait, I am not done! You see, each image in photoshop and on the web is measured by pixels. The upper left corner of an image has the coordinates of zero for the x and zero for the y. This is the orighin point of our image when we wish to measure it. The lower right corner of an image will have the same value as the image width for its x coordinate while its y coordinate will be equal to its height in pixels. When we count pixels we go the same direction as when reading any latin language - starting at the upper left corner of the page until we read the last word on the bottom right corner of the page. Here I have a rectangle that is 400 pixels wide and 400 pixels high. Let us look at few of its coordinates:
According to the above example, I can define the upper left region of the sequare (light blue) by the following coordinates: 0,0,200,200 x and y coordinates for the upper right corner followed by the x and y coordinates for the bottom left corner of the region. How would you define the region in the upper right portion (light green) of the image?
Still not sure? Try again Got it? The upper right region of the sequare (in light green) can be defined by the following values: 200,0,400,200 In photoshop open your image and from the view menu select the rulers option (A checkmark should appear next to the word Rulers) Rulers will appear to the left and above your image. Right-mouse-click (PC) or Control-Click (Mac) one of the rulers to select pixels as a unit for measurement. From the window menu select to reveal the info palette. Place your cursor over the upper left corner of the left most word in your image . DO NOT MOVE YOUR CURSOR Notice at the botom right of the info palette - the x,y values of your cursor position appear in the palette. All the words in the image have are contained within imaginary regions.
Now it is your turn to do some work. Using the method discussed above find the x,y,x,y coordinates that define the region of the word home. Do the same with the word other. (You will do the other two words later on.) write down the coordinates (x and y) of the regions. This is a good time to take a break.
Right before the closing of the body tag write the following code: <map name="navbar"> <area shape="rect" coords="x,y,x,y" href="home.htm"> <area shape="rect" coords="x,y,x,y" href="other.htm"> </map> Here is the explanation:
We are almost done! Inside the img tag add the following attribute: usemap="#navbar" Copy the code of the map and the attribute in the img tag to the rest of your pages. Your image map should now always link to home.htm and other.htm in all of the pages. Get the coordinates for the other two about and contact and add the appropriate area tags to your image maps in your pages. if you followed my example it should all work. If it does not work, go over the assignment one more time. |
|||||
back ↑ |