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

Incredible Demos

  • By
    Display Images as Grayscale with CSS Filters

    CSS filters aren't yet widely supported but they are indeed impressive and a modern need for web imagery.  CSS filters allow you to modify the display of images in a variety of ways, one of those ways being displaying images as grayscale. Doing so requires the...

  • By
    Scroll IFRAMEs on iOS

    For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari.  For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...

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!