What’s the simplest markup to display text upon clicking an image?
No toggling, CSS or Javascript. I have a series of thumbs that I would like put a caption to when clicked. I’ve been searching for hours for what seems to be so simple and I just don’t get it.
The following approach is rather simple, but it makes the image caption text visible only until something else is clicked on in the page so that a link is followed. (It’s not quite clear from the question whether this is OK.)
Make the image caption text initially invisible, using CSS. Make the image a link to its caption, and use the
:targetpseudo-class to turn the caption to visible when the link is clicked on. Demo: jsfiddle.As a side effect, the page may move down a bit, due to clicking on a link. If this is a problem, you could use “self-pointing” links instead:
and then you would modify the selector in the essential CSS rule:
This works across browsers except IE 8 and older. They can be covered using polyfill, i.e. JavaScript code that emulates support to the pseudo-element in browsers without native support. See Polyfill for css :target, not(), and [tilde] sibling selectors?