Links With Dashed Underlines

Tags tagged as   Akxl: Website  Code: CSS, Web
A method for adding link unerline styles that's better than CSS borders.

The Problem

Underline styles are not implemented in modern browsers, so the text-underline-style property of CSS will not make links have dashed underlines.

A workaround I had seen on the web was to use the border-bottom property on links, to set a 1 pixel border below the links.

1 A 2 { 3 border-bottom: 1px dashed #000000; 4 }

This gives you something like this: Sample Link.

The problem with this is that the underline is very far below the text, which is not where an underline should be. It gets very bad on larger sized text. The dashes are also very big, with a lot of space, which is not attractive. So, I invented a new solution.

Articles and downloads sponsored by:
Thanks! Amazon commissions help me pay for textbooks.

The Solution

I figured that background images would never work, because they would not scale with font sizes. However, with a little CSS, I was able to create a solution that works almost exactly the same as actual underlining with font sizes 10px to 18px, which are the only sizes I ever really link.

It also allows me to swap the underline for a solid underline on hover, which I think created a cool aesthetic effect, that looks like this: Sample Link.

Source Code

The solution uses two tiny images, which are 3x2 pixels and 50 bytes each. They are listed below, but they are small, so you'll have to squint. Click on the links provided to the right of the images to download them.

linkunderline.gif [/images/linkunderline.gif]
linkunderline_hover.gif [/images/linkunderline_hover.gif]

1 A:link, A:visited { 2 color: #003652; 3 text-decoration: none; 4 background-image: url('/images/linkunderline.gif'); 5 background-repeat: repeat-x; 6 background-position: bottom center; 7 } 8 A:active, A:hover { 9 color: #003652; 10 text-decoration: none; 11 background-image: url('/images/linkunderline_hover.gif'); 12 background-repeat: repeat-x; 13 background-position: bottom center; 14 }

Comments & Feedback


There are no comments on this entry.
Leave this field blank:
Comment on this Entry
This work is licensed under a Creative Commons Attribution 3.0 United States License.
Please link to this article in your source code comments if you use this content.

Article Info

Posted October 07, 2006
Viewed 1059 times

User Rating:

Share

Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati
Coffee Counter
Current Coffee:
 Peet's Malawi Songwe River

Current Count:
Akxl Coffee Meter

Create Your Own »

The Real-Time Coffee Meter is a free Website App from Akxl Labs. Text-only and badge versions available.