animated gif showing link hover effect

Sass Link Styling

Every website uses anchor tags to style links. This is an example of a way that you can use Sass to quickly style links. You can define the link color with your other colors for your site and then by changing the Sass $link-color variable you’ll change the color for all of your links.

This code below is intended for your main site links. You will most likely style your navigation links a bit differently with some separate CSS.

Here is the snippet of code:

SCSS

You can change $link-color in line 2 to a different color and your links will change.

If you want to set each color for the link, hover and visited states then also replace the darken(…) and lighten(…) values for $hover-color and $visited color with your own colors. For example:

SCSS

Using Transitions for Animation

CSS transitions allow you to add some movement when people hover. Here are two examples. The first one adds a background color and the second one adds an animated bottom border.

Animated Background Color

This example is relatively simple, adding a background color on hover and adding a transition to the background and padding (the padding on top and bottom gives the highlight a little breathing room).

SCSS
Animated Bottom Border

This transition is a bit more complex because we are using Scale to animate the border changing width. Because we can’t apply scale directly to the link element or the entire link will scale we’re using the :before pseudo element.

SCSS