Jan
30

How To: Add an external link image via CSS

Pop up links suck. The twitterverse also responded when asked: Should Links Open in a New Window? Twitter Web Designers Voice In. But sometimes you need to use them. Sometimes you are required by your clients to use them. Or sometimes it is best to use them. It would be nice to at least let the person know that clicking on the link will open a new window/tab. Here’s an easy way to add a little image to the external links using CSS.

The CSS

a[rel="external"], a.external {
white-space: nowrap;
padding-right: 15px;
background: url(/images/external.gif) no-repeat 100% 50%;
zoom: 1;
}

The HTML
To use the CSS, you would add the rel="external" to your html link like so:

<a href="http://www.google.com" rel="external" target="_blank">External link</a>

The Result
Here’s what the final result looks like after using the CSS and HTML. (This is an image! Not a real link.)
External Link CSS Example

Do you do this differently? Have a better solution? Please feel free share thoughts, feedback and comments.

Share the Love:
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Design Float
  • Reddit
  • DZone
  • FriendFeed
  • Twitter
  • email
  • Print

Related Posts

View Comments to “How To: Add an external link image via CSS”

|
  1. How To: Add an external link image via CSS…

    Pop up links suck. The twitterverse also responded when asked: Should Links Open in a New Window? Twitter Web Designers Voice In. But sometimes you need to use them. Sometimes you are required by your clients to use them. Or sometimes it is best to use…

  2. spinn says:

    You could just use a[target="_blank"] in the CSS, without the rel attribute.

  3. Apple Mac says:

    Very cool. Is there any way of doing this with out have to add a “rel” tag. Its going to take so long to go through hundreds of posts and add the bit of text.

  4. John Wang says:

    Yes there is. You can replace the CSS code to use a[target="_blank"] as Spinn has pointed out. I avoided that as I don't like using the target a lot. Plus, it also allows me to different images for different external links. Such as PDFs, etc.

  5. John Wang says:

    Yes. That is true. The reason why I avoided using the target=_blank, is because I also like to have different CSS images attached to separate types of external links. If I'm linking to PDFs or other such links. Including internal links that I may need to make open in new tabs/windows.

    Good point though. It is very useful if one does not want/need to use different images.

    Thanks.

  6. this is what i looking for, i think this css will help me in my customization

  7. cnelindia says:

    http://www.voip-services-provider.co.uk
    Voice over IP (VoIP) software is used to conduct telephone-like voice conversations across the internet. There are many free VOIP Software available on the webs for download. VOIP Software is popular because VOIP phone service is often cheaper than traditional phone service, and is becoming more popular for both business and personal calls.
    VoIP Services

  8. MacPress says:

    oh thank for the code big help

  9. gisnap says:

    Its really cool, I came to know this really worth visiting, just bookmarked your site.

    http://gisnap.com/
    The place where fun never ends

  10. sint4x says:

    Wow, you're making it too complicated!

    Easier way is to leave the link how it is (no rel or target attribute if you don't need it) and use:

    a[href^="www.yourdomain.com"]
    {
    /* internal links */
    }

    Enjoy :)

    `SiNT4X

  11. webaddlink says:

    Your web is very useful I liked a lot and I will return to read again.
    For my siteadd link add url

  12. Linking says:

    This article is very good. Useful to me. I will return to read this article and other article absolute sure. thank you
    For my site Linking

  13. Hans says:

    I don't get it. Clicking on this image doesn't lead me to Google…

|

Leave a Reply

blog comments powered by Disqus