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
?
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>
).
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>
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.
Nesting of 'a' will not be possible. However if you badly want to keep the structure and still make it work like the way you want, then override the anchor tag click in javascript /jquery .
so you can have 2 event listeners for the two and control them accordingly.
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