I have a <div>
block with some fancy visual content that I don't want to change. I want to make it a clickable link.
I'm looking for something like <a href="…"><div> … </div></a>
, but that is valid XHTML 1.1.
You can't make the div a link itself, but you can make an <a> tag act as a block , the same behaviour a <div> has.
You can make the entire DIV function as a link by adding an onclick="window. location='TARGET URL'" and by setting its style to "cursor:pointer". But it's often a bad idea to do this because search engines won't be able to follow the resulting link, readers won't be able to open in tabs or copy the link location, etc.
We simply add the onlcick event and add a location to it. Then, additionally and optionally, we add a cursor: pointer to indicate to the user the div is clickable. This will make the whole div clickable.
So we pushed an update to make that process less of a pain: now you can simply right click on a div block to convert it to a link block (and vice versa). Right-click to convert div blocks to link blocks (and vice versa).
Came here in the hope of finding a better solution that mine, but I don't like any of the ones on offer here. I think some of you have misunderstood the question. The OP wants to make a div full of content behave like a link. One example of this would be facebook ads - if you look, they're actually proper markup.
For me the no-nos are: javascript (shouldn't be needed just for a link, and very bad SEO/accessibility); invalid HTML.
In essence it's this:
<span></span>
, not <span />
- thanks @Campey)apply the following CSS to the empty span:
{ position:absolute; width:100%; height:100%; top:0; left: 0; z-index: 1; /* fixes overlap error in IE7/8, make sure you have an empty gif */ background-image: url('empty.gif'); }
It will now cover the panel, and as it's inside an <A>
tag, it's a clickable link
You can't make the div
a link itself, but you can make an <a>
tag act as a block
, the same behaviour a <div>
has.
a { display: block; }
You can then set the width and height on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With