With the addition of CSS3 transitions and keyframe animations it can be easy to overdo animations on your website. However, adding certain effects to main content areas can greatly enhance the experience your visitors receive.

A popular trend on the web these days are “content boxes”. These were first found on a lot of sports and news sites mainly, but have since made their way to every category of web pages. Plain, generic content boxes are effective in dividing areas of content, but can be boring if there is nothing present to visually please the user.

So lets spice those generic boxes up a little bit and add some color and unique hover animations! In this particular example we are going to be mimicking the effect found on POP’s website.

Framework

Let’s get started and lay some framework for the boxes themselves in plain HTML. We need to create each “box”:

[code] <a class="box" href="#"> </a>

Breaking news – hippos are sorta dangerous

Tonight at nine

[/code]

As for the CSS styling for these, we just need something very generic. It’s the hover effects that we are looking to add a “pop”. So initially we only need to apply the following:

[code] background: linear-gradient( white, white 50%, black 50%, black ); [/code] 

We need to make the background-size twice as tall as the element itself so on hover its just a matter of moving it up and there is no extra processes trying to load upon hover:

[code] background-size: 100% 200%; [/code] 

Here is an image from CSS-Tricks showing what is going to be happening on hover:

We actually need to make the background a tad bit taller than 200%, or else a slight bit of it will still be exposed on the element pre-hover.

Quick Recap

Here is the full CSS we have so far as well as the transition on hover:

[code] .box { background: linear-gradient( white, white 50%, #333 50%, #333 ); transition: all 0.2s ease; } .box:hover { background-position: 100% 100%; } [/code] 

Spruce-it-up

Now we need to change some font colors on the hover action:

[code] .box:hover h2 { color: #48ad26; } .box:hover h2 span { color: white; } .box:hover h3 { color: #999; } [/code] 

Actually Animating

Now for the real fun, adding in the keyframe animations. To correctly emulate the effect on the POP website we need to have a different animation for the hover-on and hover-off states to add the “bump” effect so each happens in different directions. We could do this via transitions to some extent but the fact the text moves a bit and then returns to it’s original states means we need to use keyframe animations to correctly emulate the effect shown on the POP website.

Side Note: I will be going over Keyframe Animations more in depth in a later tutorial

[code] .box @keyframes up-bump { 0% { padding-top: 2em; } 50% { padding-top: 1.5em; } 100% { padding-top: 2em; } } @keyframes down-bump { 0% { padding-top: 2em; } 50% { padding-top: 2.5em; } 100% { padding-top: 2em; } } [/code]

[code] .box { animation: down-bump 0.4s ease; } .box:hover { animation: up-bump 0.4s ease; } [/code]

Initial Bump Fix

Adding that animation on the initial state makes it run right away on page load. Could be a neat effect, could be annoying. To solve this i added a little JS as shown below in the CodePen Example.

See the Pen jvwLr by Kevin Carpenter (@KevinCarpenter) on CodePen

Paul Weinert
Author

Paul Weinert is our founder, managing principal and spirit animal. He’s one of those odd people you meet that was born in Portland, grew up here and still lives here for some reason. If you had two words to describe Paul after meeting him, we’d bet you’d use “charmingly quirky”.

Paul started GRAYBOX in February 2009, and for the first four years, GRAYBOX had a blend of a contract staffing firm and a traditional agency. GRAYBOX then hired our first employees in 2012 and has been growing ever since. Professionally, Paul has a background in internet business consulting, working especially with mid-market ecommerce, healthcare, and tech companies. He worked as a user experience designer, web developer and internet marketer. Nowadays, Paul serves as our company visionary, team mentor and head of executive leadership — Paul is extremely proud of the entire team and the company. He’s constantly humbled by the team’s awesomeness and the caring community that’s sprung up from his initial ideas.

Beyond GRAYBOX, Paul is married, has two young boys and lives in NE Portland. He’s also an active foster parent, mentors other local entrepreneurs, and volunteers on local non-profit boards. Businesswise, aside from GRAYBOX, Paul has started a few other businesses and is an active investor in the local startup scene.

For the sheer joy of it, let’s play 2 truths and a lie:

  1. Paul firmly believes that any activity would be better if on a boat.
  2. Other than this whole Internet thing, Paul has basically no other skills or expertise in anything.
  3. Paul is rare unicorn, actually born and raised in Portland.