Page

[html]初探html里的map,area图像映射

818Anson16-12-20


今天帮公司弄一个html,里面就一直图片,要在图片不同位置加不同链接,第一时间就想到html里面的map图像映射标签,第一次使用这个标签。

HTML <map> 标签

实例

带有可点击区域的图像映射:

<img src="planets.jpg" border="0" usemap="#planetmap" alt="Planets" />

<map name="planetmap" id="planetmap">
  <area shape="circle" coords="180,139,14" href ="venus.html" alt="Venus" />
  <area shape="circle" coords="129,161,10" href ="mercur.html" alt="Mercury" />
  <area shape="rect" coords="0,0,110,260" href ="sun.html" alt="Sun" />
  </map>

亲自试一试

必需的属性

属性描述
idunique_name为 map 标签定义唯一的名称。

可选的属性

属性描述
namemapname为 image-map 规定的名称。

HTML <area> 标签

实例

带有可点击区域的图像映射:

<img src="planets.jpg" border="0" usemap="#planetmap" alt="Planets" />

<map name="planetmap" id="planetmap">  
<area shape="circle" coords="180,139,14" href ="venus.html" alt="Venus" />
  <area shape="circle" coords="129,161,10" href ="mercur.html" alt="Mercury" />
  <area shape="rect" coords="0,0,110,260" href ="sun.html" alt="Sun" />
  </map>

亲自试一试

必需的属性

属性描述
alttext定义此区域的替换文本。

可选的属性

属性描述
coords坐标值定义可点击区域(对鼠标敏感的区域)的坐标。
hrefURL定义此区域的目标 URL。
nohrefnohref从图像映射排除某个区域。
shape
  • default

  • rect

  • circ

  • poly

定义区域的形状。
target
  • _blank

  • _parent

  • _self

  • _top

规定在何处打开 href 属性指定的目标 URL。


今天用到矩形的映射区域,需要注意的是coords的参数意义

<area shape="rect" coords="x1, y1,x2,y2" href=url>表示设定热点的形状为矩形,左上角顶点坐标为(X1,y1),右下角顶点坐标为(X2,y2)。


坐标可以直接使用qq自带的截图测量。


另外还有其他的形状参数

  • <area shape="circle" coords="x1, y1,r" href=url>表示设定热点的形状为圆形,圆心坐标为(X1,y1),半径为r。

  • <area shape="poligon" coords="x1, y1,x2,y2 ......" href=url>表示设定热点的形状为多边形,各顶点坐标依次为(X1,y1)、(X2,y2)、(x3,y3) ......。





来自ansion博客

2016年12月20日