March 26, 2012
<DIV> inside link (<a href="">) tag
Question by kc rajput
I want to make a div click-able and but inside this <div> i have another <div> which also should be click-able or linked.
HTML
<a href="#">
<div class="box">
<div class="plus"><img src="aaa.jpg"/></div>
</div>
</a>
CSS
.box{
float:left;
width:100px;
height:100px;
}
.plus{
float:left;
width:30px;
height:30px;
}
Can i make both <div>s to link and for different links?
and Is this proper way use div inside a href ?
Answer by Starx
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>