Search code examples
htmlhyperlinkcaption

linking an image and text


I'd like to wrap an html link tag around both and image and a caption, so something like

<a href="link"><img src="...">Caption Text</img></a>

The caption should go below the image, but I'm not sure of a good way to do that (adding a <br> works, but seems unclean). I'd like to be able to use a styled element, but I can't put a div inside of there.


Solution

  • You can wrap the caption inside a span

    <a href="link"><img src="..."/><span style="display: block;">Caption Text</span></a>
    

    http://jsfiddle.net/ZgKqF/