0

i have the following div Container (including a background image).

<div class="haus"></div>

how can i link this DIV to an url?

emitremmus
  • 101
  • 1
  • 2
  • 12

5 Answers5

3

use the <a> tag :

<a href="">
    <div class="haus"></div>
</a>
David Thomas
  • 249,100
  • 51
  • 377
  • 410
Donovan Charpin
  • 3,567
  • 22
  • 30
0

Surround the div with the a-link tag

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

Or you can use onClick

<div onClick="self.location.href='http://www.google.de'" class="haus"></div>

Or a "experimental" way is to add the div a <a> link and call it over jQuery:

<div class="haus">
   <a href="#" style="display:none;">link</a>
</div>

jQuery Script:

$(".myBox").click(function(){
   window.location=$(this).find("a").attr("href"); 
   return false;
});
Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80
  • i set the link, but it is not on right position. see here: http://schwedenladen.de in top header the little house and the words i want to link. – emitremmus Sep 25 '13 at 09:35
0

Pretty Easy , like this :

<a href="htps://www.google.com">
    <div class="haus">
        This is div
    </div>
</a>

Working fiddle : http://jsfiddle.net/xhGud/4/

The Dark Knight
  • 5,455
  • 11
  • 54
  • 95
  • i set the link, but it is not on right position. see here: http://schwedenladen.de in top header the little house and the words i want to link. – emitremmus Sep 25 '13 at 09:32
0

Use this if you want to keep the next element in the same line

<a href="htps://www.google.com">
   <div class="haus" style='display:inline-block'>
    text
   </div>
</a>

or just

<a href="htps://www.google.com">
   <div class="haus">
    text
   </div>
</a>

This is also fine withe some JS work

<div onClick="self.location.href='http://www.google.com'" class="haus"></div>
Manish Kumar
  • 10,214
  • 25
  • 77
  • 147
0

I would do it the other way around. by making the a to take all the div space. Live Fiddle

That way, it will validate under any doctype.

personally I think it's clearer that way. but, its debatable.

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%;
}
avrahamcool
  • 13,888
  • 5
  • 47
  • 58