Web geeks unite, I need help with a CSS question regarding background images?
Is there any way to place alt and title text for an image that is being called from a CSS entry as a background image?
Observing members:
0
Composing members:
0
5 Answers
No, the CSS background-image property should only be used for page design, not content. However, you can apply a CSS background to an <img> tag and set it from there.
<img alt=“Alternative” title=“Title” style=“background: back.png; width=Xpx; height: Ypx;”>
You can use the “title” attribute on any HTML element, including divs. So if you’ve got a background image on #mydiv, this’ll get you your hover text.
<div id=“mydiv” title=“I am title text! You’ll see me when you hover!”></div>
Alt text can’t be done. If you need alt text or something similar to it, you’ll have to use hackier css, html, and/or javascript workarounds.
But as @Vortico pointed out—if your image is actual content rather than a design element, you should consider using an actual image element.
What are you trying to accomplish?
@funkdaddy I’d like to know that also. Perhaps we could solve your problem another way by suggesting a better alternative.
You can put a single pixel transparent GIF in the foreground, size it to the length and width of your background image, and attach your ALT attribute anf TITLE text to it.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.