General Question

gambitking's avatar

Web geeks unite, I need help with a CSS question regarding background images?

Asked by gambitking (4206points) January 7th, 2011

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

Vortico's avatar

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;”>

lapilofu's avatar

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.

funkdaddy's avatar

What are you trying to accomplish?

Vortico's avatar

@funkdaddy I’d like to know that also. Perhaps we could solve your problem another way by suggesting a better alternative.

ETpro's avatar

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




to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther