HTML5的 <area> 标签

HTML <area> 的标签之前工作中比较少用到,以下是个人通过理解完成的demo。


一、w3c对<area> 标签的解释:

<area> 标签的 coords 属性定义了客户端图像映射中对鼠标敏感的区域的坐标。坐标的数字及其含义取决于 shape 属性中决定的区域形状。可以将客户端图像映射中的超链接区域定义为矩形、圆形或多边形等。


二、shape 的三个参数及使用说明:

1.圆形:shape="circle",coords="x,y,z"
这里的 x 和 y 定义了圆心的位置("0,0" 是图像左上角的坐标),r 是以像素为单位的圆形半径。
2.多边形:shape="polygon",coords="x1,y1,x2,y2,x3,y3,..."
每一对 "x,y" 坐标都定义了多边形的一个顶点("0,0" 是图像左上角的坐标)。定义三角形至少需要三组坐标;高纬多边形则需要更多数量的顶点。
多边形会自动封闭,因此在列表的结尾不需要重复第一个坐标来闭合整个区域。
3.矩形:shape="rectangle",coords="x1,y1,x2,y2"
第一个坐标是矩形的一个角的顶点坐标,另一对坐标是对角的顶点坐标,"0,0" 是图像左上角的坐标。请注意,定义矩形实际上是定义带有四个顶点的多边形的一种简化方法。
例如,下面的 XHTML 片段在一个 100x100 像素图像的右下方四分之一处,定义了一个对鼠标敏感的区域,并在图像的正中间定义了一个圆形区域。


PS:<area> 标签外部需要嵌套一个map标签如:<map name="planetmap" id="planetmap"> planetmap 则关联我们需要显示的图片区域。

完成后鼠标hover后的效果如下:


未经过本人允许,请勿私自转载,谢谢!

w3c官方:

http://www.w3school.com.cn/tags/att_area_coords.asp



以下是个人的demo

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>erea标签使用</title>
	<meta name="viewport" content="width=device-width,user-scalable=no">
	<link rel="stylesheet" href="css/reset.css">
</head>
<body>
	<p>鼠标指在(嘴巴、眼睛、小小黑)具体位置上,进行title提示或者href链接操作</p>
	<img src="images/timg.jpg" usemap="#planetmap" alt="Planets" />
	
	<map name="planetmap" id="planetmap">
		<!-- 多边形:shape="polygon",coords="x1,y1,x2,y2,x3,y3,..." -->
		<area shape="polygon" coords="78,112,99,112,88,130" href="###" alt="Sun1" title="我是嘴巴" />
		<area shape="polygon" coords="159,153,185,153,197,174,195,188,190,192,154,192,145,184,145,173" href="###" alt="Sun3" title="我是小小黑" />
		<!-- 矩形:shape="rectangle",coords="x1,y1,x2,y2" -->
		<area shape="rectangle" coords="70,150,113,190" href="###" alt="Sun3" title="一双小手" />
		<!-- 圆形:shape="circle",coords="x,y,z" -->
		<area shape="circle" coords="58,76,22" href="###" alt="Sun2" title="左眼睛" />
		<area shape="circle" coords="127,78,22" href="###" alt="Sun3" title="右眼睛" />
	</map>
</body>
</html>






  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="expires" content="0"> <meta http-equiv="refresh" content="60"> <meta name="keywords" content="王勃,唐代,诗人"> <meta name="robots" content="index,follow"> <title>王勃及其名诗</title> </head> <body> <header> <h1>王勃及其名诗</h1> <nav> <ul> <li><a href="#introduction">简介</a></li> <li><a href="#poems">代表作</a></li> <li><a href="#conclusion">结论</a></li> </ul> </nav> </header> <section id="introduction"> <h2>简介</h2> <p>王勃(650年-676年),字子安,唐代初期著名的文学家和政治家。其诗歌以豪放派为主,代表作有《滕王阁序》、《秋风词》等。</p> <blockquote> <p>凌波不过横塘路,但目送,芳尘去。锦瑟华年谁与度?月桥花院,琐窗朱户,只有春知处。</p> <footer> <cite>《秋风词》</cite> </footer> </blockquote> </section> <section id="poems"> <h2>代表作</h2> <article> <h3>《滕王阁序》</h3> <p>始建于唐太宗贞观元年(627年),是一座历史悠久的楼阁,位于江苏扬州市广陵区瘦西湖畔。</p> <img src="tengwangge.jpg" alt="滕王阁" usemap="#tengwangge-map"> <map name="tengwangge-map"> <area shape="rect" coords="0,0,100,100" href="https://baike.baidu.com/item/%E6%BB%95%E7%8E%8B%E9%98%81" target="_blank" alt="滕王阁百度百科"> </map> </article> <article> <h3>《秋风词》</h3> <audio src="qiu_feng_ci.mp3" controls>您的浏览器不支持 HTML5 音频元素。</audio> <video src="qiu_feng_ci.mp4" controls>您的浏览器不支持 HTML5 视频元素。</video> <ol> <li>凌波不过横塘路</li> <li>但目送,芳尘去</li> <li>锦瑟华年谁与度</li> <li>月桥花院,琐窗朱户</li> <li>只有春知处</li> </ol> </article> </section> <section id="conclusion"> <h2>结论</h2> <table> <thead> <tr> <th>作品</th> <th>类型</th> <th>评价</th> </tr> </thead> <tbody> <tr> <td>《滕王阁序》</td> <td>散文</td> <td>被誉为“千古文章”,是中国文学史上的经典之作。</td> </tr> <tr> <td>《秋风词》</td> <td>词</td> <td>王勃的词作中,这首《秋风词》被人们传颂最为广泛。</td> </tr> </tbody> </table> <form action="#" method="post" target="_blank" enctype="multipart/form-data"> <fieldset> <legend>留言板</legend> <label for="name">姓名:</label> <input type="text" id="name" name="name" required placeholder="请输入您的姓名"><br> <label for="email">邮箱:</label> <input type="email" id="email" name="email" required placeholder="请输入您的邮箱"><br> <label for="message">留言:</label> <textarea id="message" name="message" rows="4" cols="40" required placeholder="请输入您的留言"></textarea><br> <input type="submit" value="提交"> </fieldset> </form> <button onclick="alert('感谢您的阅读!')">点个赞吧</button> <canvas id="myCanvas" width="300" height="150"> 您的浏览器不支持 HTML5 画布元素。 </canvas> <style> #myCanvas { border: 1px solid black; } </style> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.font = "30px Arial"; ctx.fillText("Hello World", 10, 50); </script> <address> 联系我们:北京市海淀区中关村大街1号<br> 电话:010-12345678<br> <a href="mailto:wangbo@example.com">wangbo@example.com</a> </address> <footer> <p>版权所有 © 2021 王勃</p> </footer> </section> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值