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
    5 HTML5 APIs You Didn&#8217;t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

Incredible Demos

  • By
    Prevent Page Zooming in Mobile Browsers

    Ever since I got my iPhone, I've been more agreeable in going places that my fiancee wants to go. It's not because I have any interest in checking out women's shoes, looking at flowers, or that type of stuff -- it's because my iPhone lets...

  • By
    Introducing MooTools ScrollSpy

    I've been excited to release this plugin for a long time. MooTools ScrollSpy is a unique but simple MooTools plugin that listens to page scrolling and fires events based on where the user has scrolled to in the page. Now you can fire specific...

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!