Example of using map tags in CSS to create multiple area clicks on a single map

Source: Internet
Author: User
Tags requires

Map label

Defines a client-side image map. An image map (Image-map) refers to an image with a clickable region.

The area element is always nested inside the map element. An AREA element defines a region in an image map.

The Usemap attribute in the IMG tag can refer to the ID or name attribute in the map tag (depending on the browser), so we should add the ID and name attribute to the map label at the same time.

Example

For example, we want to implement nine hotspot areas in the following diagram, and use the map tag without cutting the graph.

First use PS to get several coordinates:

Then the code implements:

CSS Code copy content to clipboard
  1. <! DOCTYPE html>
  2. "en">
  3. <meta charset="UTF-8">
  4. <title>Document</title>
  5. <body>
  6. src="cat.jpg" alt="" usemap="#catmap" >
  7. <map name="Catmap">
  8. <area shape= "rect" coords="0,0,148,139 " "href =" http://www.baidu.com " target =" _ Blank "alt=" ">
  9. <area shape= "rect" coords="148,139,295,0 " href ="http://www.sina.com" target = " _blank " alt= "">
  10. <area shape= "rect" coords="295,0,439,140 " "href =" http://www.qq.com " target =" _ Blank "alt=" ">
  11. <area shape= "rect" coords="148,139,0,340 " "href =" http://www.163.com " target =" _ Blank "alt=" ">
  12. <area shape= "rect" coords="148,139,296,340 " href ="http://www.soso.com" target = " _blank " alt= "">
  13. <area shape= "rect" coords="296,340,439,140 " href =" http://sf.gg" target ="_blank" alt="">
  14. <area shape= "rect" coords=" 0,340,148,493" href= "target =" _ Blank "alt=" ">
  15. <area shape= "rect" coords=" 148,493,296,340" href= "target =" _ Blank "alt=" ">
  16. <area shape= "rect" coords=" 296,340,436,490" href= "http://jd.com" target ="_blank" alt="">
  17. </map>
  18. </body>

That's it.

About Area

Area can be round (CIRC), Polygon (poly), Rectangle (rect), different shapes to select different coordinates (coords).

Circle: Shape= "Circle", coords= "X,y,z"

X,y is the center coordinate (x,y), and z is the radius of the circle.

Polygon: shape= "polygon", coords= "X1,y1,x2,y2,x3,y3,..."

Each pair of x,y coordinates defines one vertex (0,0) of a polygon as the coordinate of the upper-left corner of the image. Defining a triangle requires at least three sets of coordinates, and a higher-latitude polygon requires a larger number of vertices.

Rectangle: shape= "Rectangle", coords= "X1,y1,x2,y2"

The first coordinate is the vertex coordinate of one corner of the rectangle, the other pair is the vertex coordinate of the diagonal, and "0,0" is the coordinate of the upper-left corner of the image. Note that defining a rectangle is actually a simplified way to define a polygon with four vertices. (That is, you know the coordinates of the two points on the diagonal.) )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.