<DIV> inside link (<a href="">) tag
No, the link assigned to the containing <a>
will be assigned to every elements inside it.
And, this is not the proper way. You can make a <a>
behave like a <div>
.
An Example [Demo]
CSS
a.divlink {
display:block;
width:500px;
height:500px;
float:left;
}
HTML
<div>
<a class="divlink" href="yourlink.html">
The text or elements inside the elements
</a>
<a class="divlink" href="yourlink2.html">
Another text or element
</a>
</div>
As of HTML5 it is OK to wrap <a>
elements around a <div>
(or any other block elements):
The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links).
Just have to make sure you don't put an <a>
within your <a>
( or a <button>
).
This is a classic case of divitis - you don't need a div to be clickable, just give the <a>
tag a class. Then edit the CSS of the class to display:block, and define a height and width like a lot of other answers have mentioned.
The <a>
tag works perfectly well on its own, so you don't need an extra level of mark-up on the page.