简体   繁体   English

如何使用CSS制作自定义可点击形状以覆盖所需的确切区域?

[英]How to make a custom clickable shape with CSS to cover the exact needed area?

I have to implement custom clickable area for my image in non standard shape (only for visible part of image). 我必须为非标准形状的图像实现自定义可点击区域(仅适用于图像的可见部分)。 The shape is some part of the roof. 形状是屋顶的一部分。 I want to be able to do the click action only when I will hover over the shape. 我希望仅在将鼠标悬停在形状上时才能执行单击操作。

Please see my example here in FIDDLE and see what I am doing wrong and how can it be done in better way? 请在FIDDLE中查看我的示例,看看我做错了什么以及如何以更好的方式完成它? I have a problem with selection of transform parameters and with locating the clickable area just under the shape. 我在选择变换参数以及在形状下方找到可点击区域时遇到问题。 How to do it correctly and to have an exact cover for needed shape? 如何正确地做并为所需的形状提供精确的覆盖?

Custom shape: 自定义形状:

在此处输入图片说明

Example: 例:

<div class="image">
  <div class="image_roof_left">
    <a class="link_roof_left" href="http://creation.cal24.pl/opencart/index.php?route=product/product&amp;product_id=50"></a>
    <img src="http://creation.cal24.pl/opencart/image/data/poc/dach_l1.png">
  </div>
</div>

div.image_roof_left {
    border: 1px solid;
    left: 120px;
    top: 10px;
    position: absolute;
    perspective: 150px;
    perspective-origin: 5% 0;
}
a.link_roof_left {
    background-color: rgba(0, 0, 0, 0.1);
    border: 1px solid;
    padding: 50px;
    position: absolute;
    transform: rotateX(82deg) rotateY(-19deg) rotateZ(-6deg) skewX(-63deg) skewY(2deg);
}

As jme11 suggested, its better if you use an image map, as the sides of this shape are straight lines. 正如jme11所建议的,如果使用图像映射,效果会更好,因为此形状的边是直线。

Open the image in an image editor to find out the coords. 在图像编辑器中打开图像以找出坐标。

Snippet : 片段:

 <img src="http://creation.cal24.pl/opencart/image/data/poc/dach_l1.png" usemap="#map"> <map name="map"> <area shape="poly" coords="0,164,104,132,252,8,252,0,0,164" href="example.com" /> </map> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM