Jump to content

Background-Image Buttons/Links with Large Offset


Edgewalker81

Recommended Posts

Lately I've discovered the technique of creating pretty looking buttons and links by using fixed dimensions with nice background images and giving the elements some enormous (-9999) text-indent to hide the text that keeps the box itself visible.

 

I've noticed this method used in many places, but it seems a bit like a band-aid solution.  Is there a better way to achieve this effect?  I don't like to feel like I'm working around the standards instead of working with them.

Link to comment
Share on other sites

Yeah there is a "better" way. Using text-indent to put the text off-screen means that is someone is visiting the site with images turned off, they cannot see any text! If you're prepared to introduce a non-semantic element then there is an image replacement technique that is completely accessible because it places the image over the text:

 

<h2>Hello world<span></span></h2>

h2 {position:relative; height:50px; width:200px; overflow:hidden;}
h2 span {position:absolute; top:0; left:0; width:100%; height:100%; background:url() no-repeat 0 0;}

 

The span element gets pulled over the containing element and given a background image. If you need to do this for a link, then make sure the anchor is displayed as a block and that {cursor:pointer;} is added to the span declarations. This technique is widely used and considered the most accessible. Has many advantages and the non-semantic element is not exactly a deal breaker.

 

Depending on what browser support you require, you might also want to check out "Bob Image Replacement" - http://neal.venditto.org/articles/12/bir - when the website is back up. It uses z-index and relies on more semantic html.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.