Is it possible to set the src
attribute value in CSS? At present, what I am doing is:
No you can't set the image src attribute via CSS. The closest you can get is, as you say, background
or background-image
. I wouldn't recommend doing that anyway as it would be somewhat illogical.
However, there is a CSS3 solution available to you, if the browsers you're targeting are able to use it. Use content:url
as described in Pacerier's answer. You can find other, cross-browser solutions in the other answers below.