Forum Moderators: not2easy

Message Too Old, No Replies

css display alt instead of image?

can this be done?

         

HelenDev

12:08 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Trying to tidy up a cms automatically generated text only version of a site...

This is probably a long shot, but is there a way in css to get an image to display the alt or title text instead of the image?

My code is something like this:

<div class="mydiv">
<a href="http://somelink.com">
<img src="myimg.jpg" alt="my image" />
</a>
</div>

In the text only version it would be ideal if it could spit out the alt or title tag or something, in place of the image.

Any thoughts?

[edited by: HelenDev at 12:10 pm (utc) on Aug. 23, 2006]

doodlebee

5:59 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



I've had this issue with making printable pages, where I want the image replaced with the alt text. The only way I've gotten it to work is with "display:none;". For example, in the regular HTML, you'd have something like so:

<img class="alt_img" src="image.jpg" alt="alternative text here" />
<div class="alt_text">
Alternative text here
</div>

The CSS for the regular website would be:

div.alt_text {
display:none;
}

Then the CSS for the text-only (or printable) page would be:

div.alt_image {
display:none;
}

Then, depending upon which stylesheet is called, either the image disappears, or the text does.

Don't know how much that helps, but that's how I've always done it! I haven't found any other ways to accomplish it - but I'll watch in case someome else comes along with a better idea :)

HelenDev

8:18 am on Aug 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cheers doodlebee :)

I guess I'll have to change the HTML then. I was kind of hoping for a solution where I didn't, but perhaps that's just me being lazy!