Adding Icons to Links

Version

Date

Changes

1.0

2008-01-02

Initial version.

Description

Explains how to use CSS to create clickable icons for all of your HTML hyperlinks. For example, the following screenshot came from Quadralay's website and shows how icons can be used to assist with viewing text hyperlinks.

links_with_icons.png

Goals

Keys to Making it Work

Coding It

Sample CSS code

For Reverb (and perhaps other formats), the file is webworks.css.

  /* links to nested areas (drill down) */
a[href]
{
  background: transparent url("/common/img/page.gif") no-repeat scroll right center;
  padding-right: 13px;
}

  /* links with in the same file */
a[href^="#"]
{
  background: transparent none no-repeat 0 0;
  padding-right: 0px;
}

  /* links to external websites */
a[href^="http"]
{
  background: transparent url("/common/img/www.gif") no-repeat scroll right center;
  padding-right: 13px;
}

  /* links to same website */
a[href^="/"], /* implicit */
a[href^="../"], /* out of current area, but still implicit */
a[href^="http://www.your_website.com"] /* explicit www.your_website.com */
{
  background: transparent url("/common/img/jump.gif") no-repeat scroll right center;
  padding-right: 13px;
}

  /* links that should not have a button (must remove it) */
a[class]
{
  background: transparent none no-repeat 0 0;
  padding-right: 0px;
}

Limiting Behavior to Content Areas Only

If you want to prevent hyperlinks in other parts of the website, such as navigation links and menus, then you will need to use ancestor prefixes in your CSS rules. For example, the following is an example of how to apply a CSS ancestor prefix rule so that only a portion of the hyperlinks use icons.

Sample HTML with content in div element

<html>
  <body>
    <div class="content">
      <p>Paragraph text</p>
      <li>List text</li>
      <dd>Definition description text</dd>
      <dt>Definition term text</dt>
      <blockquote>Text in blockquote</blockquote>
      <div>Text in div</div>
      Text not in anything
    </div>
  </body>
</html>

Sample CSS with ancestor prefixes added

For Reverb (and perhaps other formats), the file is webworks.css.

  /* links to nested areas (drill down) */
div.content p a[href],
div.content li a[href],
div.content dd a[href],
div.content dt a[href],
div.content blockquote a[href],
div.content div a[href],
div.content a[href]
{
  background: transparent url("/common/img/page.gif") no-repeat scroll right center;
  padding-right: 13px;
}

  /* links with in the same file */
div.content p a[href^="#"],
div.content li a[href^="#"],
div.content dd a[href^="#"],
div.content dt a[href^="#"],
div.content blockquote a[href^="#"],
div.content div a[href^="#"],
div.content a[href^="#"]
{
  background: transparent none no-repeat 0 0;
  padding-right: 0px;
}

  /* links to external websites */
div.content p a[href^="http"],
div.content li a[href^="http"],
div.content dd a[href^="http"],
div.content dt a[href^="http"],
div.content blockquote a[href^="http"],
div.content div a[href^="http"]
{
  background: transparent url("/common/img/www.gif") no-repeat scroll right center;
  padding-right: 13px;
}

  /* links to webworks.com */
div.content p a[href^="/"],
div.content li a[href^="/"],
div.content dd a[href^="/"],
div.content dt a[href^="/"],
div.content blockquote a[href^="/"],
div.content div a[href^="/"],
div.content a[href^="/"],

div.content p a[href^="../"],
div.content li a[href^="../"],
div.content dd a[href^="../"],
div.content dt a[href^="../"],
div.content blockquote a[href^="../"],
div.content div a[href^="../"],
div.content a[href^="../"],

div.content p a[href^="http://www.your_website.com"],
div.content li a[href^="http://www.your_website.com"],
div.content dd a[href^="http://www.your_website.com"],
div.content dt a[href^="http://www.your_website.com"],
div.content blockquote a[href^="http://www.your_website.com"],
div.content div a[href^="http://www.your_website.com"],
div.content a[href^="http://www.your_website.com"]
{
  background: transparent url("/common/img/jump.gif") no-repeat scroll right center;
  padding-right: 13px;
}

  /* links that should not have a button (must remove it) */
a[class]
{
  background: transparent none no-repeat 0 0;
  padding-right: 0px;
}

Adding to ePublisher Stationery

DevCenter/Projects/HTML/AddingIconsToLinks (last edited 2011-05-13 15:43:07 by LiefErickson)