[css] <DIV> inside link (<a href="">) tag

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 ?

This question is related to css html

The answer is


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.


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>).


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.


I would just format two different a-tags with a { display: block; height: 15px; width: 40px; } . This way you don't even need the div-tags...


I think you should do it the other way round. Define your Divs and have your a href within each Div, pointing to different links