【发布时间】:2015-03-16 12:08:52
【问题描述】:
我试图了解如何创建一个可以在 div 内的任何位置单击的链接,并从另一个堆栈交换问题 which can be found here. 中找到了我的问题的解决方案@
它的概念很简单,看起来应该可以工作,但我在技术上遇到了问题。具体来说,尽管光标指示已找到链接,但单击该链接不会导致页面移动。但是,右键单击我想成为链接的区域并选择“在新选项卡中打开”会将我定向到链接的内容。
HTML:
<div class="container">
hello
<a href="https://www.google.com">
<span class="link-spanner"></span>
</a>
</div>
CSS:
.container{
width:200px;
height:200px;
background-color:black;
color:white;
/*Important:*/
position:relative;
}
/*Important:*/
.link-spanner{
position:absolute;
width:100%;
height:100%;
top:0;
left: 0;
z-index: 1;
/* edit: fixes overlap error in IE7/8,
make sure you have an empty gif
background-image: url('empty.gif');*/
}
我的浏览器会识别链接但在左键单击时无法打开该链接,这是否有原因?我正在使用 chrome 版本 39。可以在 in this JSFiddle page 找到相同的行为,它来自上面提供的答案的 cmets 之一。左键单击链接不会像应有的那样将我定向到谷歌。
【问题讨论】: