Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making an entire <div> become a link?

Tags:

html

hyperlink

Is there a way to make the entire area of a <div> be a proper link?

Right now I'm doing this with javascript using the onclick but this is not good since if I middle click it (on firefox) it doesn't open at all

like image 558
shoosh Avatar asked Jan 19 '26 14:01

shoosh


2 Answers

Your best choice would probably be to turn a link into a block element.

CSS: #mylink { display: block; }

HTML: <a href="#" id="mylink">Some Content</a>

like image 153
derekerdmann Avatar answered Jan 22 '26 05:01

derekerdmann


What do you have inside the DIV? If it's just text and other inline elements, you can just do:

<div><a href="#" style="display: block;">....</a></div>
like image 45
Paolo Bergantino Avatar answered Jan 22 '26 05:01

Paolo Bergantino