你如何让整个DIV可点击进入另一个页面? [英] How do you make the entire DIV clickable to go to another page?
本文介绍了你如何让整个DIV可点击进入另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它必须是一个锚。
我知道我可以将onclick绑定到div并使其成为window.location。然而,那么......用户无法通过CONTROL +点击它来打开新标签。
我只想要一个< a>
填满了整个div。
解决方案
尝试设置锚点以在您的DIV中显示为块将其高度设置为100%,如下所示:
< style>
a {display:block;身高:100%}
#test {width:100px; height:200px;背景:红色; }
< / style>
< div id ='test'>< a href ='#'> ...< / a>< / div>
你可以在这里看到一个工作示例: http://jsbin.com/ujoca3/2/edit
Do not bind it to javascript "onclick".
It needs to be an anchor.
I know I can bind onclick to the div and make it window.location. However, then...the user cannot open a new tab by CONTROL+Clicking it.
I just want an <a>
that fills up the entire div.
解决方案
Try setting the anchor to display as a block within your DIV and setting its height to 100%, like this:
<style>
a { display: block; height: 100% }
#test { width: 100px; height: 200px; background: red; }
</style>
<div id='test'><a href='#'>...</a></div>
You can see a working example here: http://jsbin.com/ujoca3/2/edit
这篇关于你如何让整个DIV可点击进入另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文