To your question there is no pure css solution compatible with the browser. I understand that this answer does not meet your original criteria, but I decided that I would put it one way or another so that you could use it as an option.
Using pseudo-elements ( :before ) would be a logical choice for CSS3, but, alas, they do not work with img tags.
You need to do something, change the markup instead or add javascript. Assuming you can't edit the markup (sometimes you can't control the source data), but you can control javascript, you can do it with pure javascript like this:
var transparentImage = "http://rd.cas.de/tim/native/image.png"; var imageList = document.getElementsByTagName("img"); var arrImages = []; for (var i = 0; i < imageList.length; i++ ) { // store the images as is first, otherwise the list is living and // you loop forever... arrImages.push(imageList[i]); } for (i = 0; i < arrImages.length; i++ ) { // first wrap all the images in a relative positioned div. var wrapper = document.createElement('div'); var newImg = document.createElement("img"); newImg.setAttribute("src", transparentImage); newImg.style.position = "absolute"; wrapper.appendChild(newImg); wrapper.appendChild(arrImages[i].cloneNode(true)); arrImages[i].parentNode.replaceChild(wrapper, arrImages[i]); }
Here's a jsfiddle that does what you want (but with javascript).
source share