[英]How to make the visible part of png image with transparent background as a link?
我想使用带有透明背景的.png图片作为我网站上的链接。
我试过这个html:
<a href="index.html">
<img border="0" src="smiley.png" alt="smiley" width="150" height="150">
</a>
这个css:
a
{
text-decoration: none;
color: inherit;
}
但是,图像仍然可以在我的图像的透明背景上单击。
这是我想要得到的例证:
***注意:此图片仅供参考。 我100%确定我的照片有透明的背景。*
当光标仅在笑脸(可见部分)上时,如何将图像用作链接?
对于此特定图像,您可以使用带有圆圈的图像映射作为活动区域。
<map id="ImgMap0" name="ImgMap0">
<area alt="" coords="30, 32, 30" href="http://www.link.com" shape="circle" />
</map>
<img src="http://placehold.it/64x64" alt="" usemap="#ImgMap0"/>
使用css-attribute border-radius: 50%;
弯曲边(如果图像是圆形的)
尝试这样,映射技术
<map name="imgmap">
<area shape="smiley" coords="x,y,radius" href="link.html" alt="img_alt">
</map>
你也可以使用css3。 我发现这篇文章的细节和一个很好的例子
我并没有'很难'测试它,但你可以尝试一下。
CSS
.circle {
background: none repeat scroll 0 0 #CCCCCC;
/* some cross-browser css missing for border-radius */
border-radius: 100px 100px 100px 100px;
color: #FFFFFF;
display: block;
float: left;
font-size: 20px;
height: 200px;
line-height: 200px;
margin-right: 30px;
text-align: center;
width: 200px;
}
.circle-border {
background: none repeat scroll 0 0 #CCCCCC;
border: 1px solid #999999;
/* some cross-browser css missing for border-radius */
border-radius: 100px 100px 100px 100px;
color: #FFFFFF;
display: block;
float: left;
font-size: 20px;
height: 199px;
line-height: 200px;
margin-right: 30px;
text-align: center;
width: 199px;
}
HTML
<a href="#" class="circle">BUTTON</a>
<hr style="clear:both;float:left;height:1px;width:100%;" />
<a href="#" class="circle-border">BUTTON</a>
您不必使用图像映射。 我用2 <div>
s尝试了它并且它起作用了。 只是把笑脸和一个<div>
与属性onclick="window.open('yoururl')"
在主<div>
让<div>
圆形并且不可见。
HTML:
<div id="maindiv">
<img src="smiley.png" alt="" id="smiley"/>
<div id="LinkArea" onclick="window.open('https://google.com')"></div>
</div>
CSS:
#maindiv {
height: 150px;
width: 150px;
background-color: rgba(0,0,0,0);
border-radius: 100%;
z-index: 2;
position: absolute;
top: 0;
left: 0;
}
#smiley {
height: 150px;
width: 150px;
z-index: 1;
}
#LinkArea {
height: 150px;
width: 150px;
background-color: rgba(0,0,0,0);
border-radius: 100%;
cursor: pointer;
z-index: 3;
position: absolute;
top: 0;
left: 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.