I prefer to use img display:block
because pages won't render with extra blank pixels under images. However I noticed this can produce odd results. If I use display:block
on an image attached to a link that sits in a DIV
that is larger than the image the entire DIV
becomes a link.
Here is my jsfiddle example: https://jsfiddle.net/j42Ln4g8/1/
Am I using display:block
incorrectly or is there an elegant way to fix this? I know I can use an internal, wrapper DIV
that's the same dimensions as the image to solve this but I thought there might be a smarter way.
HTML
<div class="image_holder">
<a href=""><img src="http://imgur.com/a/76mr6" width="180" height="200"></a>
</div>
<div class="image_holder2">
<a href=""><img src="http://imgur.com/a/76mr6" width="180" height="200"></a>
</div>
CSS
.image_holder {
margin:20px 0px;
background-color: aquamarine;
}
.image_holder img {
display: block;
}
.image_holder2 {
margin:20px 0px;
background-color: aquamarine;
}
.image_holder2 img {
display: inline-block;
}