I want to use an entire div as a link.. without the use of "onclick"
Is this possible with a simple href
?
Thanks
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 then set the width and height on it.
You can put an <a> element inside the <div> and set it to display: block and height: 100% . @Teddy: Adding position:relative; to the div and then position: absolute; height: 100%; to the a as well... should make the entire area of the div is active. You can put all of that content inside the <a> .
The answer is definitely yes, but you will need to write javascript code for it. We can use a click handler on the div element to make it clickable.
You can put an anchor tag inside of the divs... make it the last element in the divs, and style it to be display block, and to fill up 100% width and height (you may need to specify the height). Then have it "position: absolute;" and have the outermost div "position: relative;" ...
No, div
elements cannot have the href
attribute, nor will they act like links. You can use the following in HTML5:
<a href="#"><div></div></a>
However, not all current generation browsers (notably Firefox 3.6) supports this. The other alternative is to add a absolutely positioned a
element that has 100% width and height to the div
:
div a {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
This is valid HTML4, but it won't work on older versions of IE, of course. Otherwise should accomplish what you want. See: http://www.jsfiddle.net/uRh7j/
you can't. but you could use an <a>
with style="display:block"
, wich should behave exactly like a <div>
, to replace your <div>
simple answer is no, you can use onclick
with css cursor:pointer
to get the same functionality, though.
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