整个div作为链接? [英] Entire div as a link?

查看:137
本文介绍了整个div作为链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用整个div作为链接..不使用onclick



这可能是一个简单的 href



谢谢

解决方案

不, div 元素不能具有 href 属性,也不会他们像链接一样行事。您可以在HTML5中使用以下内容:

 < a href =#>< div>< / div> ;< / A>然而,并不是所有的当代浏览器(特别是Firefox 3.6)都支持这个功能。另一种方法是向 div 添加一个具有100%宽度和高度的绝对定位的 a 元素:

  div a {
width:100%;
身高:100%;
位置:绝对;
剩下:0;
top:0;
}

这是有效的HTML4,但它不适用于旧版本的IE , 当然。否则应该完成你想要的。请参阅: http://www.jsfiddle.net/uRh7j/


I want to use an entire div as a link.. without the use of "onclick"

Is this possible with a simple href?

Thanks

解决方案

No, div elements cannot have the href attribute, nor will they act like links. You can use the following in HTML5:

<a href="#"><div></div></a>

However, not all current generation browsers (notably Firefox 3.6) supports this. The other alternative is to add a absolutely positioned a element that has 100% width and height to the div:

div a {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
}

This is valid HTML4, but it won't work on older versions of IE, of course. Otherwise should accomplish what you want. See: http://www.jsfiddle.net/uRh7j/

这篇关于整个div作为链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆