Firefox Marketplace Animated Buttons

By  on  

The Firefox Marketplace is an incredibly attractive, easy to use hub that promises to make finding and promoting awesome HTML5-powered web applications easy and convenient. While I don't work directly on the Marketplace, I am privy to the codebase (and so are you). One of the well written and elegant touches to the site is its animated button. They are comprised completely of CSS and achieve a great effect by animating box-shadow and line-height.

The HTML

These styles can be applied to A elements with the button class or actual BUTTON elements:

<a href="#" class="button" role="button">Arsenal Arsenal Arsenal</a>

Since BUTTON elements have had styling quirks in the past, you'll want to use A elements everywhere outside of forms.

The CSS

There's a lot of CSS in the basic element state, but I kept all of it to keep my demo true to the Marketplace button. Here's the magic:

a.button:link,
a.button:visited,
button,
input[type=submit],
input[type=button] {
	border: 0;
	color: white;
	display: inline-block;
	font: 600 16px/31px "Open Sans","Helvetica Neue",Arial,sans-serif;
	height: 32px;
	background-color: 
	#267CC2;
	padding: 0 24px;
	position: relative;
	text-align: center;
	text-decoration: none;
	text-shadow: 0 1px 0 rgba(0, 0, 0, .25);
	white-space: nowrap;
	border-radius: .5em;
	box-shadow: 0 2px 1px rgba(0, 0, 0, .2), inset 0 -1px 0 rgba(0, 0, 0, .2), inset 0 1px 0 0 rgba(255, 255, 255, .2);
	background-color: #267CC2;
	background-image: linear-gradient(#42A5E1, #267CC2);
	transition-property: -moz-box-shadow,-webkit-box-shadow,box-shadow,line-height;
	transition-duration: .2s,.2s,.2s,.2s;
}

a.button:hover,
a.button:focus,
button:hover,
button:focus,
input[type=submit]:hover,
input[type=button]:hover,
input[type=submit]:focus,
input[type=button]:focus {
    box-shadow: 0 4px 1px rgba(0, 0, 0, 0.2), 0 -3px 0 rgba(0, 0, 0, 0.2) inset;
	line-height: 28px;
	text-decoration: none;
}

a.button:active, button.button:active {
    box-shadow: inset 0 2px 0 0 rgba(0, 0, 0, .2), inset 0 12px 24px 6px rgba(0, 0, 0, .2), inset 0 0 2px 2px rgba(0, 0, 0, .2);
	transition-duration: .1s,.1s,.1s,.1s;
	line-height: 34px;
}

As you can probably guess, the original CSS was generated using a preprocessor (LESS, in this case). As with any piece of expertly written code, there isn't too much to explain. The animated transition is applied to box-shadow and line-height properties and the :active and :hover states trigger the animations.

I love what the AMO and Marketplace team has done with this subtle effect. Not only is the effect smooth and unique, it requires no JavaScript and uses what have now become standard effect techniques. Love it!

Recent Features

  • By
    CSS Gradients

    With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements.  CSS gradients are another step in that direction.  Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...

  • By
    CSS vs. JS Animation: Which is Faster?

    How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point...

Incredible Demos

  • By
    CSS Text Overlap

    One of the important functions of CSS is to position elements. Margin, padding, top, left, right, bottom, position, and z-index are just a few of the major players in CSS positioning. By using the above spacing...

  • By
    CSS pointer-events

    The responsibilities taken on by CSS seems to be increasingly blurring with JavaScript. Consider the -webkit-touch-callout CSS property, which prevents iOS's link dialog menu when you tap and hold a clickable element. The pointer-events property is even more JavaScript-like, preventing: click actions from doing...

Discussion

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