yandoo Posted December 14, 2012 Share Posted December 14, 2012 Hiya hopefully this is just a quickie.. Im using the following css for my header and with it is the image of my banner. #header{ position:relative; height:150px; background:#fff url(images/banner.jpg) no-repeat center top; width:100%; display:block; overflow:auto; } I need to add the alt tag to it.. How is it done? Outside or Inside the brackets and with or without "": (images/banner.jpg) alt="banner description" (images/banner.jpg alt="banner description") Also and this may sound stupid but how can I test it out to see it working by blocking the images on my site? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/271988-add-alt-tag-to-image-in-css/ Share on other sites More sharing options...
Christian F. Posted December 14, 2012 Share Posted December 14, 2012 Alt attributes are only for HTML tags, not CSS properties. The proper way of accomplishing what you want, which I assume is to have a text-version of the header visible if no images are shown, is to use a heading tag with text. Then use CSS to hide the text itself, and show only the background image instead. Quote Link to comment https://forums.phpfreaks.com/topic/271988-add-alt-tag-to-image-in-css/#findComment-1399337 Share on other sites More sharing options...
White_Lily Posted December 14, 2012 Share Posted December 14, 2012 you could also use php to see if banner.jpg exists in the given directory, if so, show the banner, if not show some text instead. Quote Link to comment https://forums.phpfreaks.com/topic/271988-add-alt-tag-to-image-in-css/#findComment-1399411 Share on other sites More sharing options...
kicken Posted December 14, 2012 Share Posted December 14, 2012 you could also use php to see if banner.jpg exists in the given directory, if so, show the banner, if not show some text instead. The point of alt text is to provide a meaningful description of what the image represents to browser that are incapable/configured not to/temporarily unable to display the requested image. Checking for the images existence with PHP doesn't do any good for that. Quote Link to comment https://forums.phpfreaks.com/topic/271988-add-alt-tag-to-image-in-css/#findComment-1399420 Share on other sites More sharing options...
yandoo Posted December 16, 2012 Author Share Posted December 16, 2012 Thank you very much for your replies. Quote Link to comment https://forums.phpfreaks.com/topic/271988-add-alt-tag-to-image-in-css/#findComment-1399647 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.