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
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • 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 Rounded Corners

    The ability to create rounded corners with CSS opens the possibility of subtle design improvements without the need to include images.  CSS rounded corners thus save us time in creating images and requests to the server.  Today, rounded corners with CSS are supported by all of...

  • 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

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