CSS Kwicks

By  on  

CSS Kwicks

One of the effects that made me excited about client side and JavaScript was the Kwicks effect.  Take a list of items and react to them accordingly when hovered.  Simple, sweet.  The effect was originally created with JavaScript but come five years later, our browsers are capable of slick, efficient animations and transitions.  All this time later, I can create this same effect using a tiny bit of CSS!

The HTML

The HTML structure of kwicks is as you'd expect:  an unordered list, list items, and any rich content you'd like within them:

<ul id="kwicks">
	<li><a class="john" href="http://en.wikipedia.org/wiki/John_lennon" title="John Lennon">John Lennon</a></li>
	<li><a class="paul" href="http://en.wikipedia.org/wiki/Paul_mccartney" title="Paul McCartney">Paul McCartney</a></li>
	<li><a class="george" href="http://en.wikipedia.org/wiki/George_harrison" title="George Harrison">George Harrison</a></li>
	<li><a class="ringo" href="http://en.wikipedia.org/wiki/Ringo_starr" title="Ringo Starr">Ringo Starr</a></li>
</ul>

No changes from the original JavaScript Kwicks structure.

The CSS

All the JavaScript Kwicks did is change element widths upon list and item hover;  luckily CSS can do all of that now!

/* structure */
#kwicks { width: 590px; overflow-x: hidden; }
#kwicks:hover li a { width: 100px; }
#kwicks li { 
	float: left; 
	overflow-x: hidden; 
	display: block; 
}
#kwicks li:hover a { width: 285px !important; }

/* individual kwicks */
#kwicks li a { 
	display: block; 
	text-indent: -9999px; 
	width: 134px; 
	height: 143px; 
	transition-property: width;
	transition-duration: 1s;
}

There's a good chunk of CSS there but there are a few things to point out:

  • I've found it best to have the UL feature overflow-x: hidden; to prevent odd line-wrapping issues, even when the math makes sense
  • Two selectors control the animation width transitions; all become the short width, except the currently hovered element, which is animated to the full width

This example features only one element within each kwick, but any number of elements and right HTML can be held within each list item.

Kwicks were the super sexy JavaScript effect five years ago, but now it can be achieved with some simple CSS.  The effect itself is still nice, it's just much easier to accomplish now!

Recent Features

  • By
    Create a CSS Cube

    CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals.  Add animation and you've got something really neat.  Unfortunately each CSS cube tutorial I've read is a bit...

  • By
    Responsive Images: The Ultimate Guide

    Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...

Incredible Demos

  • By
    jQuery Link Nudge Plugin

    A while back I debuted a tasteful mouseover/mouseout technique called link nudging. It started with a MooTools version and shortly thereafter a jQuery version. Just recently Drew Douglass premiered a jQuery plugin that aimed at producing the same type of effect.

  • By
    Implement jQuery&#8217;s hover() Method in MooTools

    jQuery offers a quick event shortcut method called hover that accepts two functions that represent mouseover and mouseout actions. Here's how to implement that for MooTools Elements. The MooTools JavaScript We implement hover() which accepts to functions; one will be called on mouseenter and the other...

Discussion

  1. This is awesome! On my browser though (Chrome) the tooltip for the image keeps popping up over the pictures on the page, making the text difficult to see.

  2. Something similar
    But this one only uses CSS :)
    http://athousandnodes.com/article/css3-sliding-bannermenu

  3. Something similar
    But this one only uses CSS3
    http://athousandnodes.com/article/css3-sliding-bannermenu

  4. Am trying to get this working in a responsive way, ie. all percentage based, but no luck..

    If you have an idea, please do chip in. It has something to do with
    http://cdpn.io/cFegm

  5. Christine

    Help please. I don’t understand about the widths. Can someone explain simply? Thanks

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!