一张图片,根据区域,跳转不同链接

我使用到了两种方法、

第一种方法,使用配合使用(定位可能没调好,代码可以参考)

参考网址
注意,map只能使用px作为单位,所以,自己看着办,好好选择。
例子:

 <img src="http://img3.imgtn.bdimg.com/it/u=4120146293,3406319282&fm=26&gp=0.jpg"  usemap='demomap' alt='demomap'/>
 <map id='demomap' name='demomap'>
   //shape指的是所选区域的形状,coords指的是区域左上角和右下角的坐标
  <area shape="rect" coords="0,0,279,303" href ="http://www.baidu.com" alt="baidu" />
  <area shape="rect" coords="279,0,600,303" href ="https://www.csdn.net/" alt="csdn" />
</map>
demomap baidu csdn

第二种方法,使用定位,a标签跳转(定位可能没调好,代码可以参考)

例子:

 <img src="http://img3.imgtn.bdimg.com/it/u=4120146293,3406319282&fm=26&gp=0.jpg"/>
 <div style="position: absolute; width: 25vw;height: 13vh; top: 0vh; left:7vw; background-image: url(about:blank);background-repeat: no-repeat;background-position: center center;">
   <a target="_blank" href="https://www.facebook.com" style="width:100%;  height: 100%; display: block;"></a>
 </div> 
 <div style="position: absolute; width: 25vw;height: 13vh; top:0vh; left:37vw; background-image: url(about:blank);background-repeat: no-repeat;background-position: center center;">
     <a target="_blank" href="https://www.baidu.com" style="width:100%;  height: 100%; display: block;"></a>
 </div> 

猜你喜欢

转载自blog.csdn.net/swallow_y/article/details/97135401