I don’t remember where I first found this tip (Hedger Wang?), but it’s a good one. If you are using image replacement, i.e. background images and negative text-indent, you may notice a dotted line appear when the link is clicked and waiting for the page to change (:focus). It’s outlining the text that happens to be wayyyyy off screen. It’s easy as pie to fix this issue.

CSS Fix

This will fix the problem in Firefox. Just drop this into your global.css file.

a:focus { -moz-outline-style: none; }/*this avoids having image replacement sections display a dotted outline*/

JavaScript Fix

This will fix the issue in the other browsers.

var theahrefs = document.getElementsByTagName('a');
//fix dotted line thing when link is OnClicked
for(var x=0;x!=theahrefs.length;x++){
theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
}


2 Responses to “Get rid of the dotted lines on links with image replacement”  

  1. 1 John Williams

    Excellent!

  2. 2 J-P Stacey

    Cool, thanks for that. Depending on the layout I’ve had some success with “overflow: hidden” on the containing element, as discussed here http://bw.watchtan.com/article/368/removing-dotted-lines-with-image-replacement . Doesn’t always work, though, so I’ll keep yours in mind too!

Leave a Reply


Powered by WP Hashcash