How can I shrink an anchor (green border) around a centered image of arbitrary (not specified) width? In other words, I want the seconds box with the green border centered, just like the first one. No floats, no absolute positioning.
- Removing line (A) centers, but the anchor box remains elsewhere and cluttered.
- Changing line (A) to block makes the anchor full-width
- No luck with adding
margin: 0 auto
to the anchor either.
— No chance beyond a (slightly dodgy) text-align center?
html
<img src="" width="123" height="100">
<hr>
<a href='#'>
<img src="" width="123" height="100">
</a>
css
img {
display: block;
background: #caa; /* red */
margin: 0 auto;
}
a {
display: inline-block; /* (A) */
border: 4px solid #aca; /* green */
}