Ali*_*Ali 3 html css image imagemap coordinates
我正在尝试学习如何用 HTML 制作一个简单的网站。目前我已经创建了一个背景图像,该图像上有多个形状。我希望图像的不同部分是可点击的链接。我了解如何查找坐标并使用图像地图,但是当我更改屏幕尺寸时,可点击链接不起作用。如何使可点击区域适用于不同的屏幕尺寸?
body, html {
height: 100%;
margin: 0;
}
.bg {
background-position: left;
background-repeat: no-repeat;
background-size: 100% 100%;
}Run Code Online (Sandbox Code Playgroud)
<div class="bg"></div>
<body>
<img src="https://cdn.pixabay.com/photo/2018/01/24/18/05/background-3104413_1280.jpg" width="100%" height="100%" usemap="workmap" class="bg">
<map name="workmap">
<area target="_blank" alt="Game1" title="Game1" href="game1.html" coords="243,133,79" shape="circle">
<area target="_blank" alt="Game2" title="Game2" href="game2.html" coords="870,147,680,33" shape="rect">
<area target="_blank" alt="Game3" title="Game3" href="game3.html" coords="889,379,80" shape="circle">
<area target="_blank" alt="CS" title="CS" href="https://code.org/educate/csp " coords="770,671,73" shape="circle">
<area target="_blank" alt="Game4" title="Game4" href="game4.html" coords="163,587,214,492,267,473,335,483,377,603,327,631,249,658,211,641" shape="poly">
</map>Run Code Online (Sandbox Code Playgroud)
谢谢!
<map>方法不是最好的方法:在 HTML 页面中使用 HTML 图像<map>/<area>系统有很多缺点。最值得注意的是,当图像本身将(应该)根据客户端屏幕尺寸进行缩放和动态调整时,将与图像相关的可点击元素调整为所需的任何尺寸显示的过程在这里根本不存在。
由于 HTML<map>元素的比例和大小是绝对的,因此它们不适用于动态大小的内容(width:80%等)。
有几个选项。您可以找到一些Javascript 系统,它们会<map>在检测到窗口(重新)大小时动态调整区域边界的大小。这些当然会增加一些开销以及页面加载的 JS 膨胀。
或者等一下,鼓声传来了……你能听到吗?
是的- š calable V埃克特摹raphics是未来表现为关于图像映射点击没有JavaScript的开销,你可以阅读他们自己的维基或在MDN。
因此,使用 SVG,您可以导入标准图像格式(例如 JPG 等),然后将其与锚点和可点击元素叠加,您可以使用类似 CSS 的样式设置样式,这比旧<map>语法提供了更多的支持和可能性,例如淡入淡出、悬停、混合和模糊,所有由于用户交互而发生在静态图像上,在任何设置点,在任何尺寸的屏幕上。
强烈推荐本教程在 HTML 图像元素上制作 SVG 可点击区域图。
(为了说明目的,链接被突出显示)
#backing {
vertical-align: middle;
margin: 0;
overflow: hidden;
}
#backing svg {
display: inline-block;
position: absolute;
top: 0; left: 0;
}Run Code Online (Sandbox Code Playgroud)
<figure id='backing'>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1280 504" preserveAspectRatio="xMinYMin meet" >
<image width="1280" height="504" xlink:href="https://cdn.pixabay.com/photo/2018/01/24/18/05/background-3104413_1280.jpg">
</image>
<a xlink:href="game1.html"><circle cx="243" cy="133" r="79" fill="#fff" opacity="0.15" /></a>
<a xlink:href="game2.html"><rect x="870" y="147" width="680" height="33" fill="#fff" opacity="0.25"/></a>
<a xlink:href="game3.html"><circle cx="889" cy="379" r="80" fill="#fff" opacity="0.1"/></a>
<a xlink:href="https://code.org/educate/csp"><circle cx="770" cy="671" r="73" fill="#fff" opacity="0.2"/></a>
<a xlink:href="game4.html"><polygon id="test" points="163,587 214,492 267,473 335,483 377,603 327,631 249,658 211,641" fill="#fff" opacity="0.3"/></a>
</svg>
</figure>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4937 次 |
| 最近记录: |