PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

html map标签是什么?html map标签的结构及具体使用方法详解

寻∝梦
寻∝梦 原创
2018-08-17 13:41:29 2865浏览

html map标签是什么?html map标签的结构及具体使用方法又有哪些?下面本篇文章主要为大家讲述了html map标签的含义和html map标签的属性的一些解释,还有html map标签的具体用法。

首先让我们来看一下html map标签是什么:

html map标签:定义一个客户端图像映射。图像映射(image-map)指带有可点击区域的一幅图像。

定义map:

<map id="im_map" name="im_map">
<area shape="rect" coords="0,0,100,100" href="url.html" />
</map>

map标签定义map,area标签定义可点击的热点,area属性;

shape:定义热点形状,可选参数 rect(矩形)、circle(圆形)、poligon(自定义形状)。

coords:定义形状路径;

当shape=rect时,四个数字依次为:起点X、起点Y、终点X、终点Y

当shape=circle时,三个数字依次为:中心点X、中心点Y、半径

当shape=poligon时,可定义多个路径点,依次为:起点X、起点Y、路径1X、路径1Y、路径2X、路径2Y......

href定义点击跳转的地址。

html map标签必需的属性:

id : unique_name : 为 map 标签定义唯一的名称。

html map标签可选的属性:

name : mapname : 为 image-map 规定的名称。

map标签在HTML中的结构:

1、coords的对应坐标不用变,只需在JS里面改变其比例就OK!

<div class="map_img">
     <img class="mapImg" usemap="mapName" src="isphoto/abc.png" alt=""  style="max-width:90%">
     <map name="mapName">
        <!-- 方形区域写法 -->
        <!-- <area shape="rect" coords="605,250,660,305" target="_blank" href ="javascript:alert(1);" alt=""/> -->
         <area shape="circle" coords="633,276,28" target="_blank" href ="javascript:alert(&#39;汽车图标&#39;);" alt=""/>
    </map>
</div>

2、如果有多张图片,一张图片对应一个map,class不用变,改变map的name值和对应的usemap值就好。name=usemap他们俩是一对CP哦,不要分开它们,给他们一样的值。

<div class="map_img">
    <img class="mapImg" usemap="mapName" src="isphoto/abc.png" alt=""  style="max-width:90%">
    <map name="mapName">
         <area shape="circle" coords="633,276,28" target="_blank" href ="javascript:alert(&#39;汽车图标&#39;);" alt=""/>
     </map>
    <!-- 一张图片对应一个name和usemap -->
    <img class="mapImg" usemap="mapName2" src="isphoto/abc.png" alt=""  style="max-width:90%">
     <map name="mapName2">
         <area shape="circle" coords="633,276,28" target="_blank" href ="javascript:alert(&#39;第二张图的汽车图标&#39;);" alt=""/>
     </map>
</div>

html标签常用在为图像的某区域添加超链接!

用法如下:

<img src ="planets.gif" alt="无法显示此图像" usemap ="#planetmap" />
<map id ="planetmap" name="planetmap">
<area shape ="rect" coords ="0,0,82,126" href ="sun.htm" alt="Sun" />
<area shape ="circle" coords ="90,58,3" href ="mercur.htm" alt="Mercury" />
<area shape ="circle" coords ="124,58,8" href ="venus.htm" alt="Venus" />
</map>

usemap属性获取标签信息, 标签定义一个链接区域,shape属性定义区域形状,coords属性定义链接区域的起点坐标和终点坐标

注释:area 元素永远嵌套在 map 元素内部。area 元素可定义图像映射中的区域。

注释:中的 usemap 属性可引用 中的 id 或 name 属性(取决于浏览器),所以我们应同时向 添加 id 和 name 属性。

【相关推荐】

HTML5标签是什么意思?HTML5标签的基本用法详解

html textarea是什么意思?如何获取textarea标签中的换行符和空格?

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。