将Div转换为链接 [英] Turn Div into Link

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

问题描述

我想把div变成链接。下面的代码在Firefox中工作正常,但在IE中鼠标指针不会对链接做出反应。有没有解决的办法?感谢。

 < html> 
< head>
< style type =text / css>
.test {
width:100%;
height:100px;
background:#666666;
}
< / style>
< / head>

< body>
< a href =http://www.google.com>
< div class =test>
kjlkjlkjkljl
< / div>
< / a>

< / body>
< / html>


解决方案

我认为IE的实际响应在这种情况下。 / p>

A div 是块级元素;因此它不应该包含在内联元素中,例如 a 。如果使用 span (代替 div )在IE和Firefox中都有效?



如果您想像链接一样查看(就光标而言),那么您可能需要使用:

  a> div,/ *请将您的标记更改为以下* / 
a> span {cursor:hand; / *用于早期版本的IE * /
cursor:pointer; / * for,我想,IE 7+和FF等。* /
}


I'm trying to turn a div into a link. The code below works fine in firefox but in IE the mouse pointer doesn't react to the link. Is there a way around this? Thanks.

<html>
<head>
<style type="text/css">
.test{
    width:100%;
    height:100px;
    background:#666666;
}
</style>
</head>

<body>
<a href="http://www.google.com">
    <div class="test">
        kjlkjlkjkljl
    </div>
</a>

</body>
</html>

解决方案

I think IE's actually responding properly in this case.

A div is a block-level element; so it shouldn't be contained within an inline-element such as, for example, an a. If you use a span (in place of div) does that work in both IE and Firefox?

If you want to make it look like a link (in terms of the cursor), then you may want to use:

a > div, /* please change your mark-up to the following */
a > span {cursor: hand; /* for earlier versions of IE */
          cursor: pointer; /* for, I think, IE 7+ and FF etc. */
}

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

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