This is not possible: The image's source is part of the markup, not CSS.
The only workaround would be having div
elements with background-image
properties instead. Those you could set from within the style sheet:
<div id="image1"></div>
#image1 { width: 100px; height: 50px; background-image: url(image.gif); }
However, with this method you lose all the img
tag's advantages like
- The ability to set an
alt
text
- Resizing
- Printing (most browsers don't print background images)
- Search engine indexing (probably)
the only other alternative is by using JavaScript, but that obviously won't work if JavaScript is disabled, which makes it a no-no in my view.