Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Sexy Link Transformations with CSS

24 Responses »

CSS Transformation Links

I was recently visiting MooTools Developer Christoph Pojer's website and noticed a sexy link hover effect:  when you hover the link, the the link animates and tilts to the left or the right.  To enhance the effect, the background color of the link is changed.  I scoped out his JavaScript file to see how he created the effect but there were no link effects in it -- the effects were being created with just CSS!

The CSS

.cpojer-links a	{
	display: inline-block;
	padding: 4px;
	outline: 0;
	color: #3a599d;
	-webkit-transition-duration: 0.25s;
	-moz-transition-duration: 0.25s;
	-o-transition-duration: 0.25s;
	transition-duration: 0.25s;
	-webkit-transition-property: -webkit-transform;
	-moz-transition-property: -moz-transform;
	-o-transition-property: -o-transform;
	transition-property: transform;
	-webkit-transform: scale(1) rotate(0);
	-moz-transform: scale(1) rotate(0);
	-o-transform: scale(1) rotate(0);
	transform: scale(1) rotate(0);
}
.cpojer-links a:hover {
	background: #3a599d;
	text-decoration: none;
	color: #fff;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	-o-border-radius: 4px;
	border-radius: 4px;
	-webkit-transform: scale(1.05) rotate(-1deg);
	-moz-transform: scale(1.05) rotate(-1deg);
	-o-transform: scale(1.05) rotate(-1deg);
	transform: scale(1.05) rotate(-1deg);
}
.cpojer-links a:nth-child(2n):hover {
  -webkit-transform: scale(1.05) rotate(1deg);
  -moz-transform: scale(1.05) rotate(1deg);
  -o-transform: scale(1.05) rotate(1deg);
  transform: scale(1.05) rotate(1deg);
}

Christoph utilized the transition functionality of each browser (since each has their own prefix.)  The transition duration is set to 250 milliseconds and the scale/rotate is given to a default setting.  The hover state is given a background color (and rounded corners to enhance the effect) and the scale/rotate are changed to tilt the link.  Lastly, even links are rotated the opposition direction just to add a bit more style!

Christoph's link effect is very creative, requires a small amount of code, and isn't an over-the-top-effect.  It's exciting to know these effects can be done with simple CSS!

Discussion

  1. July 14, 2010 @ 8:40 am

    You thief! :D

    Notice that the transforms for each browser were created automatically, not all browsers support transforms/transitions correctly yet. I just put the prefixes in there so I don’t have to in the future.

  2. July 14, 2010 @ 8:44 am

    Oh right, and setting the scale(1) rotate(0) for the initial state fixed a bug on iOS where after hovering the link disappeared for a short time.

  3. July 14, 2010 @ 9:37 am

    @Christoph:

    Why thief?

    Good tut, David. Have to practice CSS3 anyway.

  4. anton samper
    July 14, 2010 @ 9:41 am

    awesome effect, very nice!!!

  5. marco barbosa
    July 14, 2010 @ 9:42 am

    Can’t you use shorthands?

    Like:
    -moz-transition: [ || || || ]

    There’s also for -webkit..

    The code looks a bit spaghetti otherwise..

    Nice animation nevertheless !

  6. July 14, 2010 @ 10:02 am

    @Milos: I was kidding
    @Marco: I used SASS Mixins to create that output, so I never really had a look at the CSS

  7. July 14, 2010 @ 10:15 am

    That’s really cool. As an effect, that’s awesome.

    Like like like.

    Also, god, I need to start using SASS or something similar.. pssh!

  8. adrian westlake
    July 14, 2010 @ 10:15 am

    Like it, although text a little distorted (FF).

    Love your little popup search tool on text select on this site by the way

  9. July 14, 2010 @ 10:29 am

    Wow, really nice effect ;)

  10. July 14, 2010 @ 12:03 pm

    For some reason my browser crashes when I try to watch the demo, odd. Nice effect though (crashing browser: Firefox 4.0b2pre, worked in Chrome though)

  11. July 14, 2010 @ 12:18 pm

    @WouterToering: I don’t believe for one moment that Firefox would crash…hahahaha.

  12. July 14, 2010 @ 2:11 pm

    nice but it seems we’re turning back in 90ies :)

  13. July 16, 2010 @ 2:38 am

    I’ve always believed these effects should be done with CSS … Leave JavaScript for the other stuff …

    It’s nice … Doesn’t work on IE8 but who give a damn?

  14. July 16, 2010 @ 4:44 am

    IE doesn’t do cool which is a shame – fingers crossed for 9. A very nice effect, already stuck a variation on the tags section of my site :)

  15. July 16, 2010 @ 11:53 am

    Cool effect, i love it!

  16. July 17, 2010 @ 2:45 am

    @Dan: IE 9 would’t be support this kind of CSS3 effect yet, I think.
    It would be rendered like we look at it now in FF 3.x

  17. woutertoering
    July 17, 2010 @ 4:37 am

    Well it’s still happening in the latest Nightly, on Windows 7 x64.

  18. matt
    July 17, 2010 @ 5:36 pm

    I don.t really see what the big deal is. Nothing more than hover background color with changing the font color, rounded corners for FF, but not IE.

    I’m not seeing any title effect – w/IE or FF.

  19. matt
    July 17, 2010 @ 5:37 pm

    whoops thats “tilt” effect, lol.

  20. July 17, 2010 @ 5:38 pm

    @Matt: have a look at it via Safari/Chrome
    @WouterToering: Yeah, Firefox likes to Crash. Ditch Firefox, switch to Chrome or Safari =)
    @Adrian: yeah, Font-Rendering isn’t the best in every browsers at the moment.

  21. matt
    July 17, 2010 @ 5:41 pm

    Ok, gotcha.

    Neat!

    Thanks.

  22. lolki
    July 19, 2010 @ 5:20 am

    Hey ! Scipt and Style is dead ! Domaine has expired ! Wake up David !

  23. devlim
    July 19, 2010 @ 8:50 am

    Nice, but not that smooth in safari 5 when mouse leave the links.
    and very smooth in chrome~

  24. July 20, 2010 @ 1:09 pm

    very nice fx! (will microsoft get a move on & get up to speed with IE 9. ?

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!