Posts Tagged ‘tricks’

Using CSS to highlight a link

Welcome to my blog, please feel free to subscribe to my RSS feed, join me on Twitter or leave a comment.

Now you know how to add a really cool hidden link in CSS but what about if you want to make certain links stand out? Just as easy

First, when you add a link to your website we want to assign a class to it like so:

<a href=’http://www.thisismyurl.com’ class=’standout’>

In my case, I’ve labeled this link with the special tag standout which will let me affect the appearance. Next in the CSS, let’s add a special rule for it:

a.standout {
/* this is what we want the normal link to appear as */
text-decoration: none;
font-color: #990000; /* (assuming you want your link blood red */
font-weight: bolder;
}

a.standout:hover {
/* when people mouse over the link */
font-color: #000000; /* (assuming your default text is black) */
cursor: default;
text-decoration: underline;
}

In this example, I’ve made the link red but still taken the underline away. I’ve put the underline back when you mouse over the link which calls extra attention to it and shows the user there’s something interactive with the link.

How’s it work? Pretty simple really, any time your HTML calls an <a> tag with the class standout, the CSS will be loaded and in turn change the appearance of your site to accommodate the new new.

Using CSS to disguise a link.

Sometimes on a website we want to link to another section for Google or other robots but we don’t want to distract our users with too many links, how do we do it? Cascading Style Sheets and a little HTML knowledge.

First, when you add a link to your website we want to assign a class to it like so:

<a href=’http://www.thisismyurl.com’ class=’noshow’>

In my case, I’ve labeled this link with the special tag noshow which will let me affect the appearance. Next in the CSS, let’s add a special rule for it:

a.noshow {
     /* this is what we want the normal link to appear as */
     text-decoration: none;
     font-color: #000000; /* (assuming your default text is black) */
}

a.noshow:hover {
     /* when people mouse over the link */
     font-color: #000000; /* (assuming your default text is black) */
     cursor: default;
}

As you’ll see since rules cascade from in a logical order, the text-decoration rule automatically applies to the hover state since it applies to the normal state but since hover states have their own color, we have to redefine it.

There you go … now you can put links on your website that nobody knows are there.