I am trying to make a simple page: two centered thumbnails images. Each one links to its original image. Here is the code (I’ve removed some part for clarity):
<!DOCTYPE html>
<html>
<head>
<style>
.column1, .column2 {
width:50%;
float:left;
}
div img {
display:block;
margin:20px auto;
width:300px;
}
</style>
</head>
<body>
<div class="column1">
<a href="#">
<img src="maelstrom_mini.jpg" />
</a>
</div>
<div class="column2">
<a href="#">
<img src="maelstrom_mini.jpg" />
</a>
</div>
</body>
</html>
The issue is that very subtle: Each image is only 300px wide, but the anchor boxes are wider that the image it is supposed to contain. It makes the image “clickable” above its surface. I can’t figure out how to tell the anchor not to spread to all its column.
When I remove the display:block attribute in the style sheet, then it solves that issue, but my pictures are no longer centered in regards to the containing column.
What’s the correct solution to have both correct presentation?
I’ve fixed your problem,
I’ve added a wrapping div around the a and img tag setting that width to 300px, then setting the images width to 100% like so,
which can be found to work here > http://jsfiddle.net/3se2V/3/