如何链接完整的 DIV 容器
How to link a complete DIV container?
>我有以下div容器(包括背景图像)。
<div class="haus"></div>
如何将此 DIV 链接到 URL?
使用 <a>
标签:
<a href="">
<div class="haus"></div>
</a>
很简单,像这样:
<a href="htps://www.google.com">
<div class="haus">
This is div
</div>
</a>
工作小提琴 : http://jsfiddle.net/xhGud/4/
如果你想将下一个元素保留在同一行中,请使用它
<a href="htps://www.google.com">
<div class="haus" style='display:inline-block'>
text
</div>
</a>
或者只是
<a href="htps://www.google.com">
<div class="haus">
text
</div>
</a>
这对于一些JS工作也很好
<div onClick="self.location.href='http://www.google.com'" class="haus"></div>
用 a 链接标签包围div
<a href="#">
<div class="haus"></div>
</a>
或者您可以使用onClick
<div onClick="self.location.href='http://www.google.de'" class="haus"></div>
或者一种"实验性"方法是向div 添加一个<a>
链接并通过 jQuery 调用它:
<div class="haus">
<a href="#" style="display:none;">link</a>
</div>
jQuery 脚本:
$(".myBox").click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
我会反过来做。 通过a
占用所有div 空间。现场小提琴
这样,它将在任何文档类型下进行验证。
我个人认为这样更清楚。 但是,这是值得商榷的。
.HTML:
<div class="haus">
<a href="htps://www.google.com">This is link in the div</a>
</div>
.CSS:
.haus
{
background-color: azure;
height: 50px;
}
.haus a
{
display: inline-block;
width: 100%;
height: 100%;
}
相关文章:
- DIV 容器保持空白
- 如何运行javascript并每分钟重新加载DIV容器(计时器)
- Javascript 图表未插入到 DIV 容器中
- DIV 容器不可隐藏
- 检测第三方网站的动态DIV容器的大小
- 动态创建一个DIV容器
- Chrome 在隐藏和显示父 DIV 容器时重新加载嵌入的 SVG 对象
- 刷新 DIV 容器
- 如何在 javascript 中通过点从 DIV 容器中获取元素
- 将隐藏字段追加到 DIV 容器中
- Jquery 菜单:默认的活动 DIV 容器
- 如何链接完整的 DIV 容器
- 单击[提交]->隐藏DIV容器1->显示DIV容器2->加载在DIV容器2中的.PHP文件中找到的DI
- 为什么这些元素不留在它们的DIV容器中?
- 在DIV容器之外通过视点扩展图像
- Div容器隐藏在另一个Div后面,即使z-index是999
- Div变换后的Div容器高度太高
- 使用AJAX和Javascript更新Div容器
- 禁用页面上的空DIV容器
- 从父DIV容器中移除