Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn Div into Link

Tags:

html

css

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>
like image 232
usertest Avatar asked Jan 25 '10 17:01

usertest


2 Answers

Why do you want to use a div as a link?

Can't you just display your link as block?

a{
  display:block;
}

Or use a span instead of a div.

like image 144
Guillaume Flandre Avatar answered Oct 06 '22 17:10

Guillaume Flandre


As Welbog noted, the <a> and <div> elements should be reversed:

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

Then in your style, you can make the <a> tag expand to fill the entire div:

.test a {
    display: block;
    width: 100%;
    height: 100%;
}
like image 26
AaronSieb Avatar answered Oct 06 '22 16:10

AaronSieb