I know I can’t change the src attribute of an <img> tag with CSS. But is there a possiblity to hide the image from the src attribute, and set a background image on the <img> tag instead?
i thought something like that: moving the actual image with padding/text-intend etc. out of view and after that setting the background-image of the img-tag, so it looks like an other image.
Js is not an option, because it’s about templating an existing page.
You can do that by pointing the img src to a 1×1 blank gif image.
This is necessary if you don’t want to add another div since all browsers handle missing images and empty src attributes differently. (chrome will add a border around the image if the image is missing for instance.)
Then you can change the images just by changing the background-image property.
UPDATE
You can also create image sprites for that and animate them by altering the background-position property. For instance:
Lets say that you have two 50px wide images and you want the second one to show when that element is hovered. Just merge them together in one image, and the css above would do the trick.