I have a link outside a div like in the following example:
<a href="http://google.com">
<div id="Something" style="width:200px; height:100px; display:block; background-color:red; padding:0; margin:0;">
</div>
</a>
Now, the link does work on any part of the div, but it is also present outside the div, mainly to the right side of it where there isn’t anything. How can I fix this to make the link only work inside the div tag?
Here’s the code in jsfiddle: http://jsfiddle.net/BWPHS/
Note,
DIVelements aredisplay: blockby default, so you don’t need that in theDIV. What you do need to do is make theAthe same height, and resolve the padding and margin to taste.http://jsfiddle.net/BWPHS/3/
Note, as sdleihssirc notes, HTML5 does allow it (if you use the DOCTYPE). Note, to resolve the specific issue for HTML5, you would need to apply the height and width to the
Atag:http://jsfiddle.net/BWPHS/2/
And, as thirtydot points out, you can
display: inline-blockorfloat: leftthe#somethingelement and applydisplay: blockto theAand it should work perfectly for you:http://jsfiddle.net/BWPHS/6/
And you probably want to try to avoid using inline
styleattributes.