Connecting Tech Pros Worldwide Forums | Help | Site Map

How to specify alternate image??

Chittaranjan's Avatar
Member
 
Join Date: Sep 2006
Posts: 51
#1: Jul 9 '07
Hi All,

I was wondering if there is any solution to specify an alternative image when the actual image is not available. As we know to place an alternate text we are using <img src="someimage.jpg" alt="Some text"> code. So please help me out in this.

Thanks and Regards,
Chittaranjan :)
Member
 
Join Date: Jun 2007
Posts: 111
#2: Jul 9 '07

re: How to specify alternate image??


Don't know if this will work,
but you could but the image inside a div, which is the same size as the image. and then give the div a background image.

When the main image doesn't exist the background image of the div will be seen.


Note: if a image doesn't exist IE will show a little icon. so it may be better to use a another div as the main element i.e. replace IMG with div and give that a backgrouond image as well.

therefore you have two divs sitting on top of each other, each the same size, and with it's own background image. if the top div doesn't have a background image (i.e. doesn't exist) then the background image of the below div will be shown through.


This is not the best way of doing it, actually its a bad way, but its (i may be wrong) possibly the only cross browser way of doing it.
Reply