Forum Moderators: not2easy

Message Too Old, No Replies

ALT attribute

         

GeeWhizzler

4:12 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Is there a way to specify the ALT attribute in CSS for an image or anchor?

tedster

5:37 am on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, there is not -- because CSS is about rendering style, not content -- alt is alternate content for non-visula user agents. Also note that the alt attribute is not part of the standard for an anchor element.

Attribute definitions
alt = text [CS]
For user agents that cannot display images, forms, or applets, this
attribute specifies alternate text... Several non-textual elements
(IMG, AREA, APPLET, and INPUT) let authors specify alternate
text to serve as content when the element cannot be rendered
normally...The alt attribute must be specified for the IMG and AREA
elements. It is optional for the INPUT and APPLET elements.

[w3.org...]

You can, however, use a title attribute in an anchor tag, and that should generate a tool-tip when someone hovers over the anchor element.

GeeWhizzler

6:58 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Thanks tedster

So it is wise to use the title attribute for anchors to help non-visual readers.

But what about images in the case where they exist in the background? I came up with an idea to do something like this:

.alt
{
// indent outside the box
// display: none;
// etc.
}

<div id="logo">
<span class="alt">This is the logo</span>
</div>

Do you know of any alt css tricks that is better than others?

createErrorMsg

11:41 am on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Theoretically, if the image is important enough to carry information, and thus need an alt attribute, it's part of the content and shouldn't be in the background.

The only time I would background a critical content image is when it's serving as a navigation button with text in a non-standard font. In that case, I would use an image replacement [webmasterworld.com] technique, similar to what you describe.

But I wouldn't go overboard and start .alt-ing every background image on your page. Remember, an image only needs an alt attribute if it says something important that visitors using screen readers or surfing with styles off will not get without it.

cEM

xfinx

7:47 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



No, an image always needs to have a alt="" attribute.
otherwise you won't get clean through the validator..
but you can leave them empty!
[edit]
btw.
images and a tags can carry the title="" attribute

createErrorMsg

8:40 pm on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, an image always needs to have a alt="" attribute.

You mean an <img> always needs to have an alt attribute. In the case of a background image, not only does it not need one to validate, but you can't give it one, since alt is an attribute assigned to an element in the markup (which a background image is not).

cEM