23 Dec 2014
How to create a super simple Christmas landing page
This week I felt like doing something Christmas related, it seemed quite relevant. Instead of enjoying the summer sun that a New Zealand Christmas offers I decided to build an experimental landing page to share. Hope you enjoy it.
What is it?
We wanted a neat way to send our users a present for the holiday season. The obvious way to give a present is in a box that they can open. Who opens presents in a 2D space? Maybe Mario but I don’t think he’s one of our users. Here is my Christmas Landing equipped with a 3D present fully animated.
- GitHub Repository
- Hosted version of landing page - Built this by connecting the git repository to a CloudCannon website making everything updatable.
Let’s break it down.
The new version of Skeleton responsive boilerplate came out recently so I decided to use that. It gives a base which doesn’t get in the way and it is basically a better browser default. This allows me to extend it really easily, pairing their grid system with our repeatable regions means I can set up the layout and hand it off. Check it out, I highly recommend it.
The Snow Background
The Snow background adds a really nice effect. It uses a set of background images paired with CSS animations to make them move separately from one another. A full tutorial is available on designmodo.com.
The Box uses 3D transformations to align all the edges. I originally based the code off a tutorial found by googling “CSS Cube”. It goes in depth about the 3D transformations. One very important attribute to note is
transform-style: preserve-3d;, this tells the browser to act in a 3D space. If your transforms and transitions are looking very flat then this is probably what is missing. FYI, colours used are from the Google Material Design colour pallete.
This box will live in two states, ‘open’ and ‘closed’. I want the difference between the states to be a single class on the parent element. This way I can toggle between the states with just:
The closed state has 4 segments on the top all pointed inwards. This is just four divs occupying the four different quadrants of the parent square. I did it this way instead of adding more parent figures to keep things modular.
This CSS places the 4 flaps in the correct position using transforms. The Z translations are very important here. The upper flaps need to be 1px above the others to prevent any overlapping effects. Another important part are the transform origins, these say where the animations should originate from.
For the open state we want the elements to flip across from the outside edge which is where we have set the transform origin.
We have translated the elements to be all on the same Z plane. I chose 150 degrees very intentionally, if it gets too close to 180 degrees the browser can’t decide which way to rotate the flaps. The inverse rotation through the box didn’t look that realistic so I decided to use 150 degrees.
A Shadow to top it all off
Quite a simple effect gives the whole scene a lot more depth. I replicated the bottom edge of the box, extended it and changed the background.
This is where a great looking box comes alive. Everything to this point has been built using transforms and a single class change. This means that all the hard work has been done and we can just roll over some CSS transitions.
First we want to add the transitions to the original state. This will allow us to synchronise the different parts when the box is closing.
Second we want to add the transitions to the
.open state. This will allow us to synchronise the different parts when the box is opening.
You can try these out by clicking any box on this page.
All Together Again
Why would I ever use this?
This shows just how much you can achieve with CSS; 3D transformations, animations and handy boilerplates lets you get a lot done in a very short amount of time. Also it’s Christmas, and who doesn’t like to give out presents.
This landing page was a great afternoon project, plugging together a whole lot of different tutorials into a really useful resource. If you like it feel free to contribute to the GitHub Repository. I’d love to add some other branches with different holidays. If you have any questions or want to spread some cheer be sure to comment below. Merry Christmas.