<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>CSS Animation Rocks</title>
  <link href="https://cssanimation.rocks/feed.xml" rel="self"/>
  <link href="https://cssanimation.rocks"/>
  <updated>2019-05-26T00:00:00Z</updated>
  <id>https://cssanimation.rocks</id>
  <author>
    <n>Donovan Hutchinson</n>
    <email>hello@cssanimation.rocks</email>
  </author>
  <entry>
    <title>Twitter&#39;s &quot;fave&quot; animation</title>
    <link href="https://cssanimation.rocks/twitter-fave/"/>
    <updated>2015-01-17T00:00:00Z</updated>
    <id>https://cssanimation.rocks/twitter-fave/</id>
    <content type="html">&lt;p&gt;Twitter recently updated the design of their &amp;quot;fave&amp;quot; (also known as &amp;quot;fav&amp;quot;) button, introducing a new animation. Rather than rely on CSS transitions, the animation makes use of a series of images. Here&#39;s how to recreate the animation using the CSS animation &lt;code&gt;steps&lt;/code&gt; timing function.&lt;/p&gt;
&lt;h3 id=&quot;update%3A-heart&quot; tabindex=&quot;-1&quot;&gt;Update: Heart&lt;/h3&gt;
&lt;p&gt;The following technique can also be used with the new &amp;quot;Heart&amp;quot; animation, as it&#39;s handled in a similar way:&lt;/p&gt;
&lt;section class=&quot;fave demo-container tap-to-activate heart&quot;&gt;&lt;/section&gt;
&lt;p&gt;See the &lt;a href=&quot;http://codepen.io/donovanh/pen/dYqxNb&quot;&gt;live example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;illusion-of-movement&quot; tabindex=&quot;-1&quot;&gt;Illusion of movement&lt;/h2&gt;
&lt;p&gt;The effect is similar to the old &lt;a href=&quot;http://en.wikipedia.org/wiki/Zoetrope&quot;&gt;Zoetrope&lt;/a&gt; devices, which presented a series of illustrations in sequence around a cylinder. Instead of a cylinder, we display a flat series of images inside an element.&lt;/p&gt;
&lt;h2 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;Demo&lt;/h2&gt;
&lt;p&gt;Hover the star to see the animation:&lt;/p&gt;
&lt;section class=&quot;fave demo-container tap-to-activate&quot;&gt;&lt;/section&gt;
&lt;p&gt;In this example we begin by creating a series of images that will make up the animation. In this case we are using part of the image set from Twitter&#39;s fave icon animation:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/steps/twitter_fave_rectangle.png&quot; alt=&quot;Frames from Twitter&#39;s fave icon animation&quot; style=&quot;max-width:256px&quot; /&gt;
&lt;p&gt;To animate these frames, we&#39;ll need to put them into a single line. &lt;a href=&quot;https://cssanimation.rocks/images/posts/steps/twitter_fave.png&quot;&gt;This file&lt;/a&gt; has them in a single row, which means we can transition from the first frame to the last frame by positioning the background:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/steps/frames.png&quot; alt=&quot;How the background images are positioned within an element&quot; style=&quot;max-width:514px&quot; /&gt;
&lt;h3 id=&quot;steps()-timing-function&quot; tabindex=&quot;-1&quot;&gt;Steps() timing function&lt;/h3&gt;
&lt;p&gt;With most timing functions such as ease or cubic-bezier, the transition animates smoothly between the start and end states. The &lt;code&gt;steps&lt;/code&gt; timing function is different. Instead of a smooth transition, it divides up the transition into a number of steps and moves sharply between each step.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/steps/steps.png&quot; alt=&quot;How the steps function is illustrated on a graph, as a series of discrete steps&quot; style=&quot;max-width:362px&quot; /&gt;
&lt;p&gt;To begin we set up the HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;fave&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;background-image&quot; tabindex=&quot;-1&quot;&gt;Background image&lt;/h3&gt;
&lt;p&gt;With that in place we can add a little styling and position the background image:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/steps/twitter_fave.png&quot; alt=&quot;Image sprite for the animation&quot; /&gt;&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.fave&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 70px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;images/twitter_fave.png&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;hover&lt;/code&gt; state is added, which is when we specify that the background position be moved to the end of the series of images:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.fave:hover&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -3519px 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; background 1s &lt;span class=&quot;token function&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;55&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the second rule, specifying the &lt;code&gt;transition&lt;/code&gt;. In this case we want to transition the background property, run the transition for a duration of one second, make use of the &lt;code&gt;steps&lt;/code&gt; timing function. The &lt;code&gt;steps&lt;/code&gt; part includes the value &lt;code&gt;55&lt;/code&gt;, as there are 55 frames in the animation.&lt;/p&gt;
&lt;p&gt;The effect is that when we hover over the element, it jumps through the transition in 55 equal steps.&lt;/p&gt;
&lt;h3 id=&quot;why-not-a-gif%3F&quot; tabindex=&quot;-1&quot;&gt;Why not a gif?&lt;/h3&gt;
&lt;p&gt;Animated gifs could potentially be used but in this case would not be a great fit. The file size is generally worse and frame rate is difficult to control. With this method we can pause, rewind, or make all sorts of other adjustments to the animation using CSS.&lt;/p&gt;
&lt;h2 id=&quot;other-uses-of-%22steps()%22&quot; tabindex=&quot;-1&quot;&gt;Other uses of &amp;quot;steps()&amp;quot;&lt;/h2&gt;
&lt;p&gt;Animating background sprites is just one use of the &lt;code&gt;steps&lt;/code&gt; timing function. Anything that needs to be animated in a series of discrete steps is a good fit for it. You could use it to create a ticking clock for example.&lt;/p&gt;
&lt;h2 id=&quot;cheatsheet&quot; tabindex=&quot;-1&quot;&gt;Cheatsheet&lt;/h2&gt;
&lt;p&gt;If you enjoyed this article, you can &lt;a href=&quot;https://twitter.com/intent/tweet?text=Recreate%20the%20Twitter%20fave%20icon%20animation&amp;amp;url=https://cssanimation.rocks/twitter-fave/&amp;amp;original_referer=https://cssanimation.rocks&quot;&gt;share it on Twitter&lt;/a&gt; or save this handy summary cheatsheet:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/tips/twitter-fave.png&quot; alt=&quot;Share this summary on Twitter&quot; style=&quot;max-width:375px&quot; /&gt;
</content>
  </entry><entry>
    <title>Animating pseudo-elements</title>
    <link href="https://cssanimation.rocks/pseudo-elements/"/>
    <updated>2015-02-03T00:00:00Z</updated>
    <id>https://cssanimation.rocks/pseudo-elements/</id>
    <content type="html">&lt;p&gt;Pseudo-elements are like getting extra DOM elements for free. They allow us to add extra content, decoration and more to our pages without adding extra HTML, and they can be animated. In this post we&#39;ll use a pseudo-element to add a little visual flair to a button.&lt;/p&gt;
&lt;section class=&quot;shiny demo-container tap-to-activate&quot;&gt;
  &lt;button&gt;Shiny effect&lt;/button&gt;
&lt;/section&gt;
&lt;h2 id=&quot;pseudo-elements&quot; tabindex=&quot;-1&quot;&gt;Pseudo-elements&lt;/h2&gt;
&lt;p&gt;Within CSS, we can specify a pseudo-element using &lt;code&gt;::before&lt;/code&gt; or &lt;code&gt;::after&lt;/code&gt;. The pseudo-element is then inserted within your element, between the element and any content. Since it acts as an element of it&#39;s own, it can be styled, positioned and more. The code looks a bit like this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.pebble::before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  ...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.pebble::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  ...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At this point, our &lt;code&gt;.pebble&lt;/code&gt; element has two virtual elements attached, and we can style them as needed.&lt;/p&gt;
&lt;h3 id=&quot;note-on-%22%3A%3A%22-versus-%22%3A%22&quot; tabindex=&quot;-1&quot;&gt;Note on &amp;quot;::&amp;quot; versus &amp;quot;:&amp;quot;&lt;/h3&gt;
&lt;p&gt;It&#39;s generally accepted that we use the double colon &lt;code&gt;::&lt;/code&gt; to denote pseudo-elements (as opposed to pseudo-classes like :hover, :first-child). If you&#39;re adding IE8 support, it&#39;s best to use the single &lt;code&gt;:&lt;/code&gt; instead. All other browsers and newer versions of IE support the double.&lt;/p&gt;
&lt;h3 id=&quot;don&#39;t-forget-%22content%22&quot; tabindex=&quot;-1&quot;&gt;Don&#39;t forget &amp;quot;content&amp;quot;&lt;/h3&gt;
&lt;p&gt;When adding pseudo-elements, one thing to keep in mind is the need to specify the &lt;code&gt;content&lt;/code&gt; property before they can be made visible on the page. As the pseudo-element is created in an content-less state, we can trick it into appearing by using an empty &lt;code&gt;content&lt;/code&gt; like so:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.pebble::before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;
  ... more styling goes here...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should make sure the element is visible on screen.&lt;/p&gt;
&lt;h2 id=&quot;example%3A-shiny-button&quot; tabindex=&quot;-1&quot;&gt;Example: Shiny button&lt;/h2&gt;
&lt;p&gt;For this example we&#39;ll use a pseudo-element to create a shiny effect on hovering over a button. Here&#39;s an example of it in action (hover or tap to see effect).&lt;/p&gt;
&lt;section class=&quot;shiny demo-container tap-to-activate&quot;&gt;
  &lt;button&gt;Shiny effect&lt;/button&gt;
&lt;/section&gt;
&lt;p&gt;To begin, some HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Oooh SHINY&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since we&#39;re using pseudo-elements, we won&#39;t need any more HTML than this to get going. You may want to add a class to the button if styling more than one type on a page, but for now we&#39;ll use the generic element for simplicity.&lt;/p&gt;
&lt;h3 id=&quot;adding-the-sheen-effect&quot; tabindex=&quot;-1&quot;&gt;Adding the sheen effect&lt;/h3&gt;
&lt;p&gt;The shiny sheen effect is a linear gradient that passes across the button. To create this we&#39;ll use the &lt;code&gt;after&lt;/code&gt; pseudo-element, and position it in a beginning position outside the button:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;button::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;229&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 172&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 142&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;229&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 172&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 142&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;60deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 7.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The sheen effect is made up of a gradient from the button colour to white and back again. At this point it is now sitting outside the button.&lt;/p&gt;
&lt;p&gt;We&#39;ll need to hide the sheen layer so that it only shows on hover. To do this we&#39;ll set the button&#39;s &lt;code&gt;overflow&lt;/code&gt; property to &lt;code&gt;hidden&lt;/code&gt;. Since the pseudo-element is within the button, this means it&#39;s positioning outside the button won&#39;t be visible.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;button {
  background: #e5ac8e;
  color: #fff;
  font-size: 14px;
  border-radius: 0.5em;
  padding: 0 1em;
  position: relative;
  overflow: hidden;
  line-height: 32px;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;ve put in some other styling also to give the button it&#39;s own look. One thing to point out, is the use of &lt;code&gt;position: relative&lt;/code&gt;. I&#39;ve added this property so that the absolutely positioned pseudo-element will exist within the button. Without specifying the position, an absolutely positioned item will position within a parent element.&lt;/p&gt;
&lt;h2 id=&quot;adding-the-animation&quot; tabindex=&quot;-1&quot;&gt;Adding the animation&lt;/h2&gt;
&lt;p&gt;Since we&#39;ll be using an animation in this example, there are two steps involved. The first is to tell the browser to use an animation on hover. Then we&#39;ll set out exactly what that animation is using &lt;code&gt;keyframes&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Adding the hover state can be done by stacking the &lt;code&gt;after&lt;/code&gt; onto the &lt;code&gt;hover&lt;/code&gt; like so:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;button:hover::after, button:focus::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; sheen 1s forwards&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we are telling the browser than on hover, the &lt;code&gt;after&lt;/code&gt; pseudo-element is to have an &lt;code&gt;animation&lt;/code&gt;. The animation, called sheen, lasts one second and stops at the end without repeating.&lt;/p&gt;
&lt;p&gt;The order matters here. Using &lt;code&gt;::after:hover&lt;/code&gt; won&#39;t work as it&#39;ll be telling the browser to react to the hover state of the pseudo-element itself.&lt;/p&gt;
&lt;p&gt;I&#39;ve also added the focus state. This means that viewers tabbing through the page will see the sheen effect as well, without needing to hover. (Thank you, &lt;a href=&quot;https://twitter.com/simevidas&quot;&gt;Šime Vidas&lt;/a&gt;, for the tip)&lt;/p&gt;
&lt;p&gt;Let&#39;s specify &lt;code&gt;keyframes&lt;/code&gt; for this animation:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; sheen&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;60deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -9em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We only need one keyframe in this case. Since the starting position (0%) is implied by the pseudo-element&#39;s starting position, we only describe the end position. In this case the end position is across at the top-right of the button. The browser will then animate the sheen effect across for us.&lt;/p&gt;
&lt;section class=&quot;shiny demo-container tap-to-activate&quot;&gt;
  &lt;button&gt;Shiny effect&lt;/button&gt;
&lt;/section&gt;
&lt;h2 id=&quot;browser-considerations&quot; tabindex=&quot;-1&quot;&gt;Browser considerations&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;http://caniuse.com/#feat=css-animation&quot;&gt;animation property is well supported&lt;/a&gt;, as are &lt;a href=&quot;http://caniuse.com/#feat=css-gencontent&quot;&gt;pseudo-elements&lt;/a&gt;. It&#39;s always good to make sure and include &lt;code&gt;-webkit&lt;/code&gt; and &lt;code&gt;-moz&lt;/code&gt; prefixes for the &lt;code&gt;keyframes&lt;/code&gt; and any transforms.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Animating List Items</title>
    <link href="https://cssanimation.rocks/list-items/"/>
    <updated>2015-02-12T00:00:00Z</updated>
    <id>https://cssanimation.rocks/list-items/</id>
    <content type="html">&lt;p&gt;When parts of a web page change, adding some animation is a good way to help your viewers understand what&#39;s going on. Animations can announce the arrival of new content, or draw attention to content that&#39;s in the process of being removed. In this article we&#39;ll look at how this can be used to help introduce new content, by showing and hiding items in a list.&lt;/p&gt;
&lt;section class=&quot;add-to-list swing-side demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;List item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;List item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;h2 id=&quot;introducing-content&quot; tabindex=&quot;-1&quot;&gt;Introducing content&lt;/h2&gt;
&lt;p&gt;Animation can be useful when helping visitors understand when things change on your site. When content is added or removed without any animation, they can miss sudden changes and be confused. Adding subtle animations can avoid this and help by &amp;quot;announcing&amp;quot; that something is going to leave the page or be introduced to it.&lt;/p&gt;
&lt;p&gt;One example of adding or removing content is managing the content of a list. Most of the animations can be used for other sorts of content. If you find them useful, or have other ideas to add, do &lt;a href=&quot;mailto:hello@cssanimation.rocks&quot;&gt;get in touch&lt;/a&gt;, we love to hear your thoughts.&lt;/p&gt;
&lt;h2 id=&quot;setting-up-the-html&quot; tabindex=&quot;-1&quot;&gt;Setting up the HTML&lt;/h2&gt;
&lt;p&gt;To get started we&#39;ll use a pre-filled list and a button to add new items to the list.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;show&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;List item&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;show&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;List item&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;add-to-list&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Add a list item&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A few things to note. Firstly we have two IDs in the HTML. Generally we don&#39;t use IDs for styling, as they can introduce problems with their specificity. However they&#39;re useful when using JavaScript.&lt;/p&gt;
&lt;p&gt;The initial items have the class &amp;quot;show&amp;quot;, as this is a class we&#39;ll use later to add the animation effect.&lt;/p&gt;
&lt;h2 id=&quot;a-little-javascript&quot; tabindex=&quot;-1&quot;&gt;A little JavaScript&lt;/h2&gt;
&lt;p&gt;For the purpose of the demo we&#39;ll create a little JavaScript to add a new item to the list, then add the &amp;quot;show&amp;quot; class so that the animation can take place. There&#39;s a reason for using this two-step process. If the list items were added in a visible state, there wouldn&#39;t be any time for the transition to take place.&lt;/p&gt;
&lt;p&gt;We could get around this by using an animation on the &lt;code&gt;li&lt;/code&gt; elements, but this would be more difficult to override when removing the elements with another animation.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/*
 * Add items to a list - from cssanimation.rocks/list-items/
 */
document.getElementById(&#39;add-to-list&#39;).onclick = function() {
  var list = document.getElementById(&#39;list&#39;);
  var newLI = document.createElement(&#39;li&#39;);
  newLI.innerHTML = &#39;A new item&#39;;
  list.appendChild(newLI);
  setTimeout(function() {
    newLI.className = newLI.className + &amp;quot; show&amp;quot;;
  }, 10);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;no-animation&quot; tabindex=&quot;-1&quot;&gt;No animation&lt;/h2&gt;
&lt;p&gt;At it&#39;s most basic we can write some CSS to show the list items. We&#39;re using the &lt;code&gt;show&lt;/code&gt; class as a way of setting them as visible, so removing the &lt;code&gt;show&lt;/code&gt; class should also cause them to disappear.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;li {
  list-style: none;
  background: #d1703c;
  color: #fff;
  height: 0;
  line-height: 2em;
  margin: 0;
  padding: 0 0.5em;
  overflow: hidden;
  width: 10em;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;li.show&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2px 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In these styles we&#39;re setting up the &lt;code&gt;li&lt;/code&gt; elements to look like rectangles, without the bullet points and giving them a &lt;code&gt;height&lt;/code&gt; of 0, a &lt;code&gt;margin&lt;/code&gt; of 0 and set &lt;code&gt;overflow&lt;/code&gt; to hidden. This is so that they will appear invisible until we apply a &lt;code&gt;show&lt;/code&gt; class.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;show&lt;/code&gt; class applies a height and margin. Since we&#39;re not using animation yet, the items should appear suddenly on the page, like so. Also try pressing the list items to see them disappear.&lt;/p&gt;
&lt;section class=&quot;add-to-list demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;List item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;List item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;h3 id=&quot;fade&quot; tabindex=&quot;-1&quot;&gt;Fade&lt;/h3&gt;
&lt;p&gt;As a first animation we&#39;ll add a simple fade effect. The list items appear a little more gradually than before. Visually this still looks a little clunky but has the benefit of giving viewers longer to notice that something is happening.&lt;/p&gt;
&lt;section class=&quot;add-to-list fade demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;List item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;List item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;p&gt;To add the effect I&#39;ve created a separate snippet of CSS. To have this apply to the list, apply the class &lt;code&gt;fade&lt;/code&gt; to a container surrounding your list.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.fade li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; all 0.4s ease-out&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.fade li.show&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;slide-down-%26-fade&quot; tabindex=&quot;-1&quot;&gt;Slide down &amp;amp; Fade&lt;/h3&gt;
&lt;p&gt;The sudden jump each time an item is added or removed is a litle jarring. Let&#39;s have the height adjust as well, to create a smoother sliding effect.&lt;/p&gt;
&lt;section class=&quot;add-to-list slide-fade demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;List item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;List item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;p&gt;The difference between this and the &lt;code&gt;fade&lt;/code&gt; class above is only that the &lt;code&gt;height: 2em&lt;/code&gt; has been removed. Since the &lt;code&gt;show&lt;/code&gt; class contains a set height (inherited from the first CSS snippet), it will transition the height automatically.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.slide-fade li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; all 0.4s ease-out&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.slide-fade li.show&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;swinging-in&quot; tabindex=&quot;-1&quot;&gt;Swinging in&lt;/h3&gt;
&lt;p&gt;Along with fading and sliding, we can go further by adding a little 3D effect. Browser can transform elements in more than the X or Y directions, useful for adding depth to scenes.&lt;/p&gt;
&lt;section class=&quot;add-to-list swing demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;List item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;List item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;p&gt;To set this up, we need to define the containing &lt;code&gt;section&lt;/code&gt; as a stage within which the 3D transitions take place. We do this by giving it a &lt;code&gt;perspective&lt;/code&gt; value.&lt;/p&gt;
&lt;p&gt;Perspective in CSS is the depth of the scene. A lower number means a more shallow perspective, with more extreme angles. It&#39;s worth playing with this value to find a look that works for you.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.swing&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next we set up the &lt;code&gt;li&lt;/code&gt; elements to transform into place. We&#39;ll use &lt;code&gt;opacity&lt;/code&gt; to create a fade effect as before, but add in a &lt;code&gt;transform&lt;/code&gt; to rotate the &lt;code&gt;li&lt;/code&gt; into place.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.swing li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; all 0.5s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.36&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;-0.64&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.34&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1.76&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.swing li.show&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; all 0.5s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.36&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;-0.64&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.34&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1.76&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example we&#39;re beginning with the &lt;code&gt;li&lt;/code&gt; rotated back by 90 degrees. When the &lt;code&gt;show&lt;/code&gt; class it added, this &lt;code&gt;transform&lt;/code&gt; is set to &lt;code&gt;none&lt;/code&gt;, allowing it to transition into place. To give it a swinging effect I&#39;ve used the &lt;code&gt;cubic-bezier&lt;/code&gt; timing function.&lt;/p&gt;
&lt;h3 id=&quot;swinging-from-side&quot; tabindex=&quot;-1&quot;&gt;Swinging from side&lt;/h3&gt;
&lt;p&gt;We can tweak this effect to create different styles quite easily. Here&#39;s an example where the items swing in from the side.&lt;/p&gt;
&lt;section class=&quot;add-to-list swing-side demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;List item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;List item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;p&gt;To create this effect we only need change the axis of rotation.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.swing li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; all 0.5s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.36&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;-0.64&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.34&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1.76&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All we&#39;ve changed is &lt;code&gt;rotateX&lt;/code&gt; to &lt;code&gt;rotateY&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;prefixes-and-browser-testing&quot; tabindex=&quot;-1&quot;&gt;Prefixes and browser testing&lt;/h2&gt;
&lt;p&gt;The code included above does not include any prefixes, for readability. It&#39;s strongly recommended to add prefixes to support browsers that need the &lt;code&gt;-webkit&lt;/code&gt; prefix or others. I use &lt;a href=&quot;https://github.com/postcss/autoprefixer&quot;&gt;Autoprefixer&lt;/a&gt; to save worrying about these things.&lt;/p&gt;
&lt;p&gt;As these animations are layered on top of the basic show / hide mechanism, they should degrade gracefully on browsers that don&#39;t support the animations. Testing on various devices and browsers is important but most modern browsers should be able to support these animations.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Baymax in CSS</title>
    <link href="https://cssanimation.rocks/baymax/"/>
    <updated>2015-02-18T00:00:00Z</updated>
    <id>https://cssanimation.rocks/baymax/</id>
    <content type="html">&lt;p&gt;Let&#39;s use CSS to create the Baymax character from the movie Big Hero 6.&lt;/p&gt;
&lt;p&gt;In this post we&#39;ll be animating a background image, as well as a subtle animation timing effect, and make a CSS demo out of one single HTML element.&lt;/p&gt;
&lt;section class=&quot;demo-container baymax-container&quot;&gt;
  &lt;a href=&quot;http://codepen.io/donovanh/full/ZYaMjw/&quot; class=&quot;baymax&quot;&gt;&lt;/a&gt;
&lt;/section&gt;
&lt;p&gt;You can &lt;a href=&quot;http://codepen.io/donovanh/full/ZYaMjw/&quot;&gt;see it full screen here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;single-element&quot; tabindex=&quot;-1&quot;&gt;Single element&lt;/h2&gt;
&lt;p&gt;By making use of pseudo-elements, we&#39;ll be able to create the face parts using one HTML element.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;baymax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;styling&quot; tabindex=&quot;-1&quot;&gt;Styling&lt;/h2&gt;
&lt;p&gt;To set the stage we&#39;ll add a subtle gradient to the screen to make it look like a curved, white head. For this we&#39;ll use a radial gradient on the &lt;code&gt;body&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;body {
  background: radial-gradient(circle at
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;center, #fff, #fff 50%, #aaa);&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  background-size: 100% 100%;
  background-repeat: no-repeat;
  height: 100vh;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next we position the face in the centre of the page. The mouth is a simple black line, and we&#39;ll create that using a border.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.5em solid #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -40%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first property sets a black border of width &lt;code&gt;1.5em&lt;/code&gt;. It then positions the line using absolute positioning, pushing it down 50% and across from the left 50%. These 50% values relate to the size of the container (&lt;code&gt;body&lt;/code&gt;) element.&lt;/p&gt;
&lt;p&gt;The problem we now have is that the element now starts halfway down and halfway across the screen. It&#39;s off center.&lt;/p&gt;
&lt;p&gt;To offset this, we use a transform to pull the element left 50% of it&#39;s width, and up 40% of it&#39;s width.&lt;/p&gt;
&lt;p&gt;At this stage the mouth is centered like so:&lt;/p&gt;
&lt;section class=&quot;demo-container baymax-container&quot;&gt;
  &lt;span class=&quot;baymax no-pseudo-elements&quot;&gt;&lt;/span&gt;
&lt;/section&gt;
&lt;h2 id=&quot;adding-the-eyes&quot; tabindex=&quot;-1&quot;&gt;Adding the eyes&lt;/h2&gt;
&lt;p&gt;We&#39;ll make use of the &lt;code&gt;before&lt;/code&gt; and &lt;code&gt;after&lt;/code&gt; pseudo-elements to add eyes to the face. This won&#39;t need any extra HTML and is entirely handled by the CSS.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax::before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -9em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-4deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -9em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each of these pseudo-elements have a black background, and a border-radius of 50% to make them circular. Each is positioned at an end of the mouth, and lastly have a &lt;code&gt;skew&lt;/code&gt; transform to make them look like they&#39;re tilted back a little. The result should look like this:&lt;/p&gt;
&lt;section class=&quot;demo-container baymax-container&quot;&gt;
  &lt;span class=&quot;baymax no-animation&quot;&gt;&lt;/span&gt;
&lt;/section&gt;
&lt;h2 id=&quot;low-battery&quot; tabindex=&quot;-1&quot;&gt;Low battery&lt;/h2&gt;
&lt;p&gt;There&#39;s a funny scene in the movie where Baymax&#39;s battery runs low. He staggers around and his eyelids droop. We can use a combination of background gradients and animation to create the effect.&lt;/p&gt;
&lt;p&gt;First we want to give the background two colours. Black for the part of the eye that&#39;s open, and white for the eyelid. The white part needs to be positioned outside the eyes at first, then we will animate it in to make the eyelids droop.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax::before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #efefef&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #efefef 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 -100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200% 200%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  ...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #efefef&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #efefef 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 -100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200% 200%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  ...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;re adding a background linear gradient, made it twice the height of the container, and then position it so that the top half is outside the container.&lt;/p&gt;
&lt;p&gt;With the two background gradients in place, we can add animation &lt;code&gt;keyframes&lt;/code&gt; to control the eyelids movement.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; blink&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 50%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;85%, 95%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 75%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;background-position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Animation &lt;code&gt;keyframes&lt;/code&gt; are a way of describing a series of frames, using a percentage. The percentage relates to how long the animation has gone on for. So a percentage of 50% means half-way through the animation.&lt;/p&gt;
&lt;p&gt;In this way we can set the background to stay up till half-way through, then between 50% and 85%, it moves down, and then snaps back at the end of the animation.&lt;/p&gt;
&lt;p&gt;The next step is to tell the pseudo-elements to use these animation keyframes. Add the &lt;code&gt;animation&lt;/code&gt; property to the existing styles.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax::before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; blink 6s infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  ...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.baymax::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; blink 6s 0.1s infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  ...
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&#39;ve told the browser to use the &lt;code&gt;blink&lt;/code&gt; animation on each element. The animation duration is set to six seconds and will loop infinitely.&lt;/p&gt;
&lt;p&gt;One extra property is in the second example. The &lt;code&gt;0.1s&lt;/code&gt; after the &lt;code&gt;6s&lt;/code&gt; tells the browser to delay that animation by 0.1 seconds. This creates the effect of the second eye closing slightly later than the first. It adds to the tired, droopy effect and makes it look a little more human. The end result should look like this:&lt;/p&gt;
&lt;section class=&quot;demo-container baymax-container&quot;&gt;
  &lt;a href=&quot;http://codepen.io/donovanh/full/ZYaMjw/&quot; class=&quot;baymax&quot;&gt;&lt;/a&gt;
&lt;/section&gt;
&lt;p&gt;You can &lt;a href=&quot;http://codepen.io/donovanh/full/ZYaMjw/&quot;&gt;see the effect full screen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;browsers&quot; tabindex=&quot;-1&quot;&gt;Browsers&lt;/h2&gt;
&lt;p&gt;In the code examples, I&#39;ve omitted any of the usual &lt;code&gt;-webkit&lt;/code&gt; and &lt;code&gt;-moz&lt;/code&gt; prefixes. The &lt;code&gt;transform&lt;/code&gt; and &lt;code&gt;animation&lt;/code&gt; properties should be prefixed, and I&#39;d recommend using something like Autoprefixer for this.&lt;/p&gt;
&lt;h2 id=&quot;shareable-gif-version&quot; tabindex=&quot;-1&quot;&gt;Shareable gif version&lt;/h2&gt;
&lt;p&gt;Here&#39;s an animated gif version you can more easily share online.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cssanimation.rocks/images/posts/baymax/baymax.gif&quot;&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/baymax/baymax.gif&quot; style=&quot;max-width:225px&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
</content>
  </entry><entry>
    <title>Clocks</title>
    <link href="https://cssanimation.rocks/clocks/"/>
    <updated>2015-02-25T00:00:00Z</updated>
    <id>https://cssanimation.rocks/clocks/</id>
    <content type="html">&lt;p&gt;It&#39;s about time. In this article we&#39;ll take on the challenge of creating and animating a clock, using simple CSS animations as well as JavaScript to trigger them.&lt;/p&gt;
&lt;p&gt;This is the clock we&#39;ll create using HTML, CSS, an SVG background and a little JavaScript. We&#39;ll use CSS animations or transitions for any movement, and rely on JavaScript to set the initial time and adding basic CSS transforms.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single local bounce&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;html&quot; tabindex=&quot;-1&quot;&gt;HTML&lt;/h3&gt;
&lt;p&gt;To get started we&#39;ll need some HTML.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;article&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;clock&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;hours-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;hours&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;minutes-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;minutes&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;seconds-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;seconds&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;article&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My initial approach was to use three elements for each of the hands. I then went back and wrapped each in a container element. While the simpler HTML worked as far as the basic CSS animations, we&#39;ll need containing elements when we want to position the hands and  animate them also.&lt;/p&gt;
&lt;h2 id=&quot;clock-face&quot; tabindex=&quot;-1&quot;&gt;Clock face&lt;/h2&gt;
&lt;p&gt;We&#39;ll begin with a basic clock design has a round face, with simple hours, minutes and seconds hands.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.clock&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #fff &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;/images/posts/clocks/ios_clock.svg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 88%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 31%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.clock.simple:after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -50%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can &lt;a href=&quot;https://cssanimation.rocks/images/posts/clocks/ios_clock.svg&quot;&gt;get the SVG background here&lt;/a&gt;. I&#39;ve also added a pseudo-element to add a solid black circle to the center. The hands of the clock can then be placed behind this pseudo-element as needed.&lt;/p&gt;
&lt;p&gt;We should now have something like this.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;&lt;/article&gt;
&lt;/div&gt;
&lt;p&gt;Before adding the hands, we need to place the containers.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.minutes-container, .hours-container, .seconds-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This stacks each container on top of the clock. Next we create the hands.&lt;/p&gt;
&lt;h3 id=&quot;hour-hand&quot; tabindex=&quot;-1&quot;&gt;Hour hand&lt;/h3&gt;
&lt;p&gt;Each hand is given the position property of &lt;code&gt;absolute&lt;/code&gt; and placed in the twelve o&#39;clock position. We&#39;ll begin with the hour hand.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.hours&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 48.75%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;m using percentages to make scaling the clocks easier. It&#39;s a bit more work but makes it easier to have them fit the view or shrink down for mobiles. We also set the &lt;code&gt;transform-origin&lt;/code&gt; property to the bottom of the hand so that it can be rotated later.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;minute-hand&quot; tabindex=&quot;-1&quot;&gt;Minute hand&lt;/h3&gt;
&lt;p&gt;The minute hand is similar, but taller and thinner.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.minutes&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 40%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 49%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;demo-container clocks single&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;second-hand&quot; tabindex=&quot;-1&quot;&gt;Second hand&lt;/h3&gt;
&lt;p&gt;The second hand is thinner again, but also set further down so that it extends further than the center. To allow for this the &lt;code&gt;transform-origin&lt;/code&gt; to 80%. This leaves 20% of the hand extending past the center.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.seconds&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 45%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 49.5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 14%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 80%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 8&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;demo-container clocks single&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;animation&quot; tabindex=&quot;-1&quot;&gt;Animation&lt;/h3&gt;
&lt;p&gt;A stopped clock is only going to be right twice a day. Let&#39;s add some animations to make the clock behave more like the real thing.&lt;/p&gt;
&lt;p&gt;Some clocks jump along with each second, usually making a ticking sound. Some clocks purr along with the hands moving smoothly. We&#39;ll try both. First, we&#39;ll make the hands move smoothly.&lt;/p&gt;
&lt;p&gt;We can use one &lt;code&gt;keyframe&lt;/code&gt; to tell the hands to move around 360 degrees (the 0% starting position is implied).&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; rotate&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This keyframe tells the element to animate around 360 degrees, if applied to the element using the &lt;code&gt;animation&lt;/code&gt; property. We&#39;ll use a &lt;code&gt;linear&lt;/code&gt; timing function on the hand to make the hands move smoothly.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.hours-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate 43200s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.minutes-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate 3600s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.seconds-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate 60s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;hours&lt;/code&gt; hand is set to rotate once every 12 hours (43,200 seconds). The minute hand rotates once per hour, and the second hand once every minute.&lt;/p&gt;
&lt;p&gt;Put it together and we now have movement!&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single linear&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;p&gt;If you are very sharp-eyed, you might be able to even make out the minute hand moving. It would take an hour for it to complete a rotation, and twelve hours for the hour hand to complete it&#39;s circuit.&lt;/p&gt;
&lt;p&gt;The second hand takes 60 seconds, so it easier to notice.&lt;/p&gt;
&lt;h3 id=&quot;adding-steps&quot; tabindex=&quot;-1&quot;&gt;Adding steps&lt;/h3&gt;
&lt;p&gt;We can make the hands behave more like a normal clock by having the second hand move around the clock in 60 separate movements. A simple way to achieve this is using the &lt;code&gt;steps&lt;/code&gt; timing function. The &lt;code&gt;animation&lt;/code&gt; property for each hand then becomes:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.minutes-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate 3600s infinite &lt;span class=&quot;token function&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;60&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.seconds-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate 60s infinite &lt;span class=&quot;token function&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;60&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Both the minute and seconds hand now move around in sixty steps. The browser automatically calculates how far each of these 60 steps move.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single steps&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;the-correct-time&quot; tabindex=&quot;-1&quot;&gt;The correct time&lt;/h3&gt;
&lt;p&gt;It&#39;s all very well having the time look good, but how about being accurate? With a little JavaScript we can have the time be correct for our visitors. Here&#39;s the code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/*
  * Starts any clocks using the user&#39;s local time
  * From: cssanimation.rocks/clocks
  */
function initLocalClocks() {
  // Get the local time using JS
  var date = new Date;
  var seconds = date.getSeconds();
  var minutes = date.getMinutes();
  var hours = date.getHours();
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;  // Create an object with each hand and it&#39;s angle in degrees
  var hands = [
    {
      hand: &#39;hours&#39;,
      angle: (hours * 30) + (minutes / 2)
    },
    {
      hand: &#39;minutes&#39;,
      angle: (minutes * 6)
    },
    {
      hand: &#39;seconds&#39;,
      angle: (seconds * 6)
    }
  ];
  // Loop through each of these hands to set their angle
  for (var j = 0; j &amp;lt; hands.length; j++) {
    var elements = document.querySelectorAll(&#39;.&#39; + hands[j].hand);
    for (var k = 0; k &amp;lt; elements.length; k++) {
        elements[k].style.webkitTransform = &#39;rotateZ(&#39;+ hands[j].angle +&#39;deg)&#39;;
        elements[k].style.transform = &#39;rotateZ(&#39;+ hands[j].angle +&#39;deg)&#39;;
        // If this is a minute hand, note the seconds position (to calculate minute position later)
        if (hands[j].hand === &#39;minutes&#39;) {
          elements[k].parentNode.setAttribute(&#39;data-second-angle&#39;, hands[j + 1].angle);
        }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This function converts the time (hours, minutes and seconds) into the corresponding angle for each hand. It then loops through each hand and applies that angle using the &lt;code&gt;style.transform&lt;/code&gt; property of &lt;code&gt;rotateZ&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will work on most browsers, except Safari or other browsers needing a prefix. To allow for this we also use the &lt;code&gt;style.webkitTransform&lt;/code&gt; property.&lt;/p&gt;
&lt;p&gt;This then sets the clock to the current system time.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single steps local no-bounce&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;aligning-second-and-minute-hands&quot; tabindex=&quot;-1&quot;&gt;Aligning second and minute hands&lt;/h3&gt;
&lt;p&gt;We need to make sure that the minute hand moves when the second hand hits the twelve o&#39;clock position.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/clocks/twelve.gif&quot; alt=&quot;Minute hand moving when second hand hits 12&quot; style=&quot;max-width: 180px&quot; /&gt;
&lt;p&gt;When the clock is first drawn on screen there is less than one minute before the minute hand needs to move. To allow for this, we can calculate how long until this first minute ends and manually nudge the hand along. Since we&#39;re using JavaScript to make this first movement, we can continue rotating it by six degrees every minute using &lt;code&gt;setInterval&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Before we move the minute hand we need to communicate how far into the current minute we are. You may have noticed these lines.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;if (hands[j].hand === &#39;minutes&#39;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  elements[k].parentNode.&lt;span class=&quot;token function&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;data-second-angle&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; hands[j + 1].angle&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These extra lines check to see if the hand is the &amp;quot;minutes&amp;quot; hand, and if so, sets a data attribute with the current angle of the seconds hand.&lt;/p&gt;
&lt;p&gt;With this data attribute set, we can then use this data to work out when to move the minute hand.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/*
 * Set a timeout for the first minute hand movement (less than 1 minute), then rotate it every minute after that
 */
function setUpMinuteHands() {
  // Find out how far into the minute we are
  var containers = document.querySelectorAll(&#39;.minutes-container&#39;);
  var secondAngle = containers[0].getAttribute(&amp;quot;data-second-angle&amp;quot;);
  if (secondAngle &amp;gt; 0) {
    // Set a timeout until the end of the current minute, to move the hand
    var delay = (((360 - secondAngle) / 6) + 0.1) * 1000;
    setTimeout(function() {
      moveMinuteHands(containers);
    }, delay);
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;/*
 * Do the first minute&#39;s rotation
 */
function moveMinuteHands(containers) {
  for (var i = 0; i &amp;lt; containers.length; i++) {
    containers[i].style.webkitTransform = &#39;rotateZ(6deg)&#39;;
    containers[i].style.transform = &#39;rotateZ(6deg)&#39;;
  }
  // Then continue with a 60 second interval
  setInterval(function() {
    for (var i = 0; i &amp;lt; containers.length; i++) {
      if (containers[i].angle === undefined) {
        containers[i].angle = 12;
      } else {
        containers[i].angle += 6;
      }
      containers[i].style.webkitTransform = &#39;rotateZ(&#39;+ containers[i].angle +&#39;deg)&#39;;
      containers[i].style.transform = &#39;rotateZ(&#39;+ containers[i].angle +&#39;deg)&#39;;
    }
  }, 60000);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;adding-bounce&quot; tabindex=&quot;-1&quot;&gt;Adding bounce&lt;/h3&gt;
&lt;p&gt;Since we&#39;re now using JavaScript to move the minute hand, we should remove the animation property. Rather than simply remove it, we can replace it with a transition. This is an opportunity to add a bit more character to the animation.&lt;/p&gt;
&lt;p&gt;When the JavaScript sets a new angle for the hand, a CSS transition on the element will tell the browser to animate this new position. This means that the JavaScript only deals with the simple angle changes and the browser can take care of animating it.&lt;/p&gt;
&lt;p&gt;Before we do that, we should update the code to use JavaScript to move the seconds hand also. Let&#39;s use this code to animate the seconds hands containers sixty times per minute.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/*
 * Move the second containers
 */
function moveSecondHands() {
  var containers = document.querySelectorAll(&#39;.seconds-container&#39;);
  setInterval(function() {
    for (var i = 0; i &amp;lt; containers.length; i++) {
      if (containers[i].angle === undefined) {
        containers[i].angle = 6;
      } else {
        containers[i].angle += 6;
      }
      containers[i].style.webkitTransform = &#39;rotateZ(&#39;+ containers[i].angle +&#39;deg)&#39;;
      containers[i].style.transform = &#39;rotateZ(&#39;+ containers[i].angle +&#39;deg)&#39;;
    }
  }, 1000);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With both the seconds and minute hands handled by JavaScript, update the CSS to replace the &lt;code&gt;animation&lt;/code&gt; properties with &lt;code&gt;transitions&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.minutes-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transform 0.3s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.4&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;2.08&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.55&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.44&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.seconds-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transform 0.2s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.4&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;2.08&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.55&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.44&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These transitions apply to the &lt;code&gt;transform&lt;/code&gt; property and use the &lt;code&gt;cubic-bezier&lt;/code&gt; timing function. This timing function gives the hands some bounce.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single local bounce&quot;&gt;
  &lt;article class=&quot;clock simple&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;h3 id=&quot;ios-7-style&quot; tabindex=&quot;-1&quot;&gt;iOS 7 Style&lt;/h3&gt;
&lt;p&gt;I&#39;m a big fan of the simplicity of the clock used in Apple&#39;s iOS 7. They&#39;ve since elongated the hands, but I prefer the shorter version.&lt;/p&gt;
&lt;p&gt;By styling the hands and adding a background image with the numbers, we can easily create this look.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single local bounce&quot;&gt;
  &lt;article class=&quot;clock ios7&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;p&gt;This design is itself an evolution of the &lt;a href=&quot;https://www.youtube.com/watch?v=IvIvKiDWDks&quot;&gt;Swiss Railway Clock&lt;/a&gt; by Hans Hilfiker. By changing a few styles and adding a new background image we can adapt our clock to this style.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single local bounce&quot;&gt;
  &lt;article class=&quot;clock station&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;p&gt;If you come up with other designs, do &lt;a href=&quot;mailto:hello@cssanimation.rocks&quot;&gt;let me know&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;using-moment.js&quot; tabindex=&quot;-1&quot;&gt;Using Moment.js&lt;/h2&gt;
&lt;p&gt;One of my first ideas when planning this post was to recreate the hotel clocks scene, with three clocks showing different time zones.&lt;/p&gt;
&lt;p&gt;The easiest way to adjust for different time zones is by using the amazing &lt;a href=&quot;http://momentjs.com/timezone/&quot;&gt;Moment.js Timezone&lt;/a&gt; library.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks multiple active bounce&quot;&gt;
  &lt;article class=&quot;clock station js-new-york&quot;&gt;
```js
&lt;div class=&quot;label&quot;&gt;New York&lt;/div&gt;
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
  &lt;article class=&quot;clock station js-london&quot;&gt;
```js
&lt;div class=&quot;label&quot;&gt;London&lt;/div&gt;
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
  &lt;article class=&quot;clock station js-tokyo&quot;&gt;
```js
&lt;div class=&quot;label&quot;&gt;Tokyo&lt;/div&gt;
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;p&gt;You can see the code in action &lt;a href=&quot;http://codepen.io/donovanh/full/vEjywy/&quot;&gt;on this Codepen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;browser-compatibility&quot; tabindex=&quot;-1&quot;&gt;Browser compatibility&lt;/h2&gt;
&lt;p&gt;Modern browsers can handle the CSS transitions and animations involved. IE10+, recent Chrome and Firefox support them without prefixes, and Safari requires the &lt;code&gt;-webkit&lt;/code&gt; prefix.&lt;/p&gt;
&lt;p&gt;Don&#39;t forget to use the prefixed properties within JavaScript too.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Transitions vs Animations</title>
    <link href="https://cssanimation.rocks/transition-vs-animation/"/>
    <updated>2015-03-04T00:00:00Z</updated>
    <id>https://cssanimation.rocks/transition-vs-animation/</id>
    <content type="html">&lt;p&gt;When animating on the web, do you use a transition or an animation? There are times when you would want to choose one over the other. Let&#39;s discuss the differences.&lt;/p&gt;
&lt;h2 id=&quot;what-are-transitions%3F&quot; tabindex=&quot;-1&quot;&gt;What are Transitions?&lt;/h2&gt;
&lt;p&gt;A transition occurs when an element changes from one state to another, and the browser fills in that state change with a sequence of in-between frames. It has a beginning and an end state.&lt;/p&gt;
&lt;p&gt;We most often see transitions used on hover states, or when information on a page is added or removed. The hover states might be a subtle change in font color, and information on the page might fade from invisible to visible.&lt;/p&gt;
&lt;p&gt;Since transitions are limited to these two stages, they can lack the nuance of animations but at the same time be easier to use.&lt;/p&gt;
&lt;h3 id=&quot;when-to-use-them&quot; tabindex=&quot;-1&quot;&gt;When to use them&lt;/h3&gt;
&lt;p&gt;If you want to change an element from one state to another smoothly, a transition is a good choice. Simple changes can usually be handled with transitions and timing functions can be used to customize the way the transition occurs.&lt;/p&gt;
&lt;p&gt;A transition would work well when someone hovers or taps a button:&lt;/p&gt;
&lt;section class=&quot;shiny demo-container tap-to-activate&quot;&gt;
  &lt;button&gt;Shiny effect&lt;/button&gt;
&lt;/section&gt;
&lt;p&gt;Or when an item is added to a page:&lt;/p&gt;
&lt;section class=&quot;add-to-list swing demo-container&quot;&gt;
  &lt;ul&gt;
```html
&lt;li class=&quot;show&quot; style=&quot;background-color: #d13c9e;&quot;&gt;A list item&lt;/li&gt;
&lt;li class=&quot;show&quot; style=&quot;background-color: #3cd19e;&quot;&gt;A list item&lt;/li&gt;
```
  &lt;/ul&gt;
  &lt;button&gt;Add a list item&lt;/button&gt;
&lt;/section&gt;
&lt;h2 id=&quot;what-are-animations%3F&quot; tabindex=&quot;-1&quot;&gt;What are Animations?&lt;/h2&gt;
&lt;p&gt;CSS Animations are a more powerful alternative to transitions. Rather than rely on a change from one beginning state to an end state, animations can be made up of as many in-between states as you like, and offer more control over how the states are animated.&lt;/p&gt;
&lt;p&gt;Where a transition only goes from A to B, an animation can go from A, B, C to D. Or any number of stages as needed.&lt;/p&gt;
&lt;p&gt;Animations achieve this by using sets of &lt;code&gt;keyframes&lt;/code&gt;. Where a transition can be specified with one line in the class, an animation works by referencing a set of keyframes that are described separately in the CSS.&lt;/p&gt;
&lt;h3 id=&quot;when-to-use-them-1&quot; tabindex=&quot;-1&quot;&gt;When to use them&lt;/h3&gt;
&lt;p&gt;If an animation needs to run when the page loads, or is more complex than a simple A to B state change, a CSS animation might be more appropriate.&lt;/p&gt;
&lt;p&gt;Examples of this might be if you want to have an animation on the page that plays after a certain amount of time, like this blink effect on this Baymax character:&lt;/p&gt;
&lt;section class=&quot;demo-container baymax-container&quot;&gt;
  &lt;a href=&quot;http://codepen.io/donovanh/full/ZYaMjw/&quot; class=&quot;baymax&quot;&gt;&lt;/a&gt;
&lt;/section&gt;
&lt;p&gt;An animation might also be a good choice if an item has to move across multiple places on the page, such as an instruction overlay with a mouse cursor point out various areas of interest on a screen.&lt;/p&gt;
&lt;h2 id=&quot;sometimes-it&#39;s-not-obvious&quot; tabindex=&quot;-1&quot;&gt;Sometimes it&#39;s not obvious&lt;/h2&gt;
&lt;p&gt;A recent post began as an animation, but then became a case for transitions.&lt;/p&gt;
&lt;div class=&quot;demo-container clocks single local bounce&quot;&gt;
  &lt;article class=&quot;clock station&quot;&gt;
```html
&lt;div class=&quot;hours-container&quot;&gt;
  &lt;div class=&quot;hours angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;minutes-container&quot;&gt;
  &lt;div class=&quot;minutes angled&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;seconds-container&quot;&gt;
  &lt;div class=&quot;seconds&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/div&gt;
&lt;p&gt;When I began designing this clock, I had the hands move continuously on load. This was a good case for using the &lt;code&gt;animation&lt;/code&gt; property. It was to animate on load and continue forever. When I started adding more complexity, I found it made more sense to have the hands&#39; angles set using JavaScript.&lt;/p&gt;
&lt;p&gt;As the hands were being moved by JavaScript, &lt;code&gt;transitions&lt;/code&gt; became a better choice. When the JavaScript changes the angle of a hand, the CSS &lt;code&gt;transition&lt;/code&gt; handles the change (from state A to state B) more elegantly than an animation would.&lt;/p&gt;
&lt;p&gt;Check out this &lt;a href=&quot;https://cssanimation.rocks/clocks/&quot;&gt;CSS clock tutorial&lt;/a&gt; for more detail.&lt;/p&gt;
&lt;h2 id=&quot;in-summary&quot; tabindex=&quot;-1&quot;&gt;In summary&lt;/h2&gt;
&lt;p&gt;Transitions for creating a smooth transition from one state to another, and animations for more complex series of movements.&lt;/p&gt;
&lt;p&gt;Transitions are generally easier to create and manage, and apply to the majority of situations. If you need more control over animating an element through a series of steps, or if the animation needs to begin on load, then an animation with keyframes might be the better choice.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Apple Watch Dials</title>
    <link href="https://cssanimation.rocks/watch/"/>
    <updated>2015-03-09T00:00:00Z</updated>
    <id>https://cssanimation.rocks/watch/</id>
    <content type="html">&lt;p&gt;With the announcement of Apple&#39;s new watch this week, I thought I&#39;d take a look at creating the activity dials using CSS.&lt;/p&gt;
&lt;p&gt;In this post we&#39;ll make use of CSS keyframe animations and a bit of &lt;code&gt;overflow&lt;/code&gt; trickery to create the radial progress bars shown in the activities section of Apple&#39;s new watch.&lt;/p&gt;
&lt;h2 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;Demo&lt;/h2&gt;
&lt;p&gt;Here&#39;s an example of the final effect.&lt;/p&gt;
&lt;section class=&quot;demo-container watch-container&quot;&gt;
  &lt;article class=&quot;watch&quot;&gt;
```html
&lt;div class=&quot;bg-image&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;screen&quot;&gt;
  &lt;header&gt;
    &lt;span class=&quot;title&quot;&gt;Activity&lt;/span&gt;
    &lt;span class=&quot;time&quot;&gt;10:09&lt;/span&gt;
  &lt;/header&gt;
  &lt;section class=&quot;dials&quot;&gt;
    &lt;div class=&quot;dial move&quot;&gt;
      &lt;div class=&quot;dial-background one&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;dial-container container1&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;dial-container container2&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;dial exercise&quot;&gt;
      &lt;div class=&quot;dial-background two&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;dial-container container1&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;dial stand&quot;&gt;
      &lt;div class=&quot;dial-background three&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;dial-container container1&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;
  &lt;section class=&quot;pips&quot;&gt;
    &lt;div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;/div&gt;
  &lt;/section&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/section&gt;
&lt;h2 id=&quot;radial-progress-bars&quot; tabindex=&quot;-1&quot;&gt;Radial progress bars&lt;/h2&gt;
&lt;p&gt;The watch&#39;s activity display is made up of 3 dials. Each is a kind of progress bar, shaped to curve around a circle. It&#39;s a little tricky to create this shape, but it can be done using two wedges and some carefully timed animation.&lt;/p&gt;
&lt;p&gt;We&#39;ll begin with a simple half-circle wedge shape.&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example0&quot;&gt;
```html
&lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Here&#39;s the HTML for this wedge:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We set up the wedge to be a half-moon shape using the &lt;code&gt;border-radius&lt;/code&gt; property and rotate it using a &lt;code&gt;keyframe&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.wedge&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate 4s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 4em 4em 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; red&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0% 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; rotate&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;masking&quot; tabindex=&quot;-1&quot;&gt;Masking&lt;/h2&gt;
&lt;p&gt;In earlier experiments, I&#39;d tried creating this effect using the CSS &lt;code&gt;clip&lt;/code&gt; property. This did work in some browsers, but it&#39;s a deprecated property and tricky to use. Instead, we can create a similar effect by using &lt;code&gt;overflow: hidden&lt;/code&gt; on the container.&lt;/p&gt;
&lt;p&gt;There are two elements in play here. The &lt;code&gt;dial-container&lt;/code&gt; is half as wide as the &lt;code&gt;wedge&lt;/code&gt;, and has it&#39;s &lt;code&gt;overflow&lt;/code&gt; property set to &lt;code&gt;hidden&lt;/code&gt;. By placing it outside the container, we can rotate it into view.&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example1&quot;&gt;
```html
&lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.dial-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The container is positioned to the right of where the wedge is positioned, and the wedge is then rotated into view.&lt;/p&gt;
&lt;p&gt;To create the full circle we need to create a second wedge. We can create this by creating a second container, placed on the left and rotating a wedge into it from the right.&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example2&quot;&gt;
```html
&lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;We can then put these together and create a circular dial. We&#39;ll also add some animation to have the second half of the dial start moving after the first dial.&lt;/p&gt;
&lt;h2 id=&quot;full-circle&quot; tabindex=&quot;-1&quot;&gt;Full circle&lt;/h2&gt;
&lt;p&gt;Here&#39;s the HTML for these two parts. I&#39;ve added a wrapper so that I can position both the containers on top of each other.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container container1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container container2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the CSS to handle the wrapper, containers and the two wedges.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.wrapper&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 2em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dial-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.wedge&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; red&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.container1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.container1 .wedge&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate-bg-1 4s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 4em 4em 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.container2&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.container2 .wedge&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate-bg-2 4s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em 0 0 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;/* First animation moves 180 degrees in the first 2 seconds */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; rotate-bg-1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;50%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;/* Second animation moves 180 degrees in the last 2 seconds */&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; rotate-bg-2&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 50%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result should look like this:&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example3&quot;&gt;
```html
&lt;div class=&quot;dial-container container1&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;dial-container container2&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;h2 id=&quot;progress&quot; tabindex=&quot;-1&quot;&gt;Progress&lt;/h2&gt;
&lt;p&gt;The next step is to make the wedge into a bar. We can do this by masking the middle. Adding a circular &lt;a href=&quot;https://cssanimation.rocks/pseudo-elements/&quot;&gt;pseudo-element&lt;/a&gt; to a container, set to the background colour, has the desired effect.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container container1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container container2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.wrapper::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #fff&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We now have something that looks more like Apple&#39;s activity radial progress bars.&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example4&quot;&gt;
```html
&lt;div class=&quot;dial-container container1&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;dial-container container2&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;h2 id=&quot;rounding-the-edges&quot; tabindex=&quot;-1&quot;&gt;Rounding the edges&lt;/h2&gt;
&lt;p&gt;The Apple Watch demo features nicely rounded ends on its progress bars. To recreate this we&#39;ll add and animate some elements on each end of the bar. To begin we add the extra elements.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container container1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dial-container container2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wedge&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;marker start&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;marker end&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;start&lt;/code&gt; marker will remain at the beginning, and the &lt;code&gt;end&lt;/code&gt; marker needs to be animated to keep pace with the front of the progress bar. We can handle that with some CSS.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.marker&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; green&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 0.25em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.end&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate-marker 4s infinite linear&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; rotate-marker&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This CSS sets up the two markers to be green circles, and positions them at the top middle of the screen. The &lt;code&gt;end&lt;/code&gt; marker then gets the &lt;code&gt;rotate-marker&lt;/code&gt; animation and has its &lt;code&gt;transform-origin&lt;/code&gt; set to the centre of the container. This means than when it rotates, it will spin around an arc.&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example5&quot;&gt;
```html
&lt;div class=&quot;dial-container container1&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;dial-container container2&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Changing the colour of the markers to red lets them blend in with the bar and give it a rounded effect. Adding a little cubic-bezier tweaking to the animation can give it a bit more character also.&lt;/p&gt;
&lt;section class=&quot;demo-container&quot;&gt;
  &lt;div class=&quot;example example6&quot;&gt;
```html
&lt;div class=&quot;dial-container container1&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;dial-container container2&quot;&gt;
  &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
&lt;/section&gt;
&lt;h2 id=&quot;putting-it-all-together&quot; tabindex=&quot;-1&quot;&gt;Putting it all together&lt;/h2&gt;
&lt;p&gt;Three of these radial progress bars together creates the Apple Watch activity dials. If you want to see more of this code, a full demo &lt;a href=&quot;http://codepen.io/donovanh/full/GgYEBZ/&quot;&gt;is available on Codepen&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&quot;demo-container watch-container&quot;&gt;
  &lt;article class=&quot;watch&quot;&gt;
```html
&lt;div class=&quot;bg-image&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;screen&quot;&gt;
  &lt;header&gt;
    &lt;span class=&quot;title&quot;&gt;Activity&lt;/span&gt;
    &lt;span class=&quot;time&quot;&gt;10:09&lt;/span&gt;
  &lt;/header&gt;
  &lt;section class=&quot;dials&quot;&gt;
    &lt;div class=&quot;dial move&quot;&gt;
      &lt;div class=&quot;dial-background one&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;dial-container container1&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;dial-container container2&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;dial exercise&quot;&gt;
      &lt;div class=&quot;dial-background two&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;dial-container container1&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;dial stand&quot;&gt;
      &lt;div class=&quot;dial-background three&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;dial-container container1&quot;&gt;
        &lt;div class=&quot;wedge&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;marker start&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;marker end&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;
  &lt;section class=&quot;pips&quot;&gt;
    &lt;div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;/div&gt;
  &lt;/section&gt;
&lt;/div&gt;
```
  &lt;/article&gt;
&lt;/section&gt;
</content>
  </entry><entry>
    <title>Animation Principles for the Web</title>
    <link href="https://cssanimation.rocks/principles/"/>
    <updated>2015-03-21T00:00:00Z</updated>
    <id>https://cssanimation.rocks/principles/</id>
    <content type="html">&lt;p&gt;As front-end designers and developers, we use CSS to style, position and create great looking sites. We often use CSS to add movement to pages in the form of transitions or even animations, but we don&#39;t usually go much beyond that.&lt;/p&gt;
&lt;p&gt;Animation can be a powerful tool to help our visitors and customers understand and benefit from our designs. There are principles we can apply to our work to make the most of this power.&lt;/p&gt;
&lt;p&gt;Long established as fundamental working practices at Disney, the &lt;a href=&quot;http://en.wikipedia.org/wiki/12_basic_principles_of_animation&quot;&gt;12 Principles of Animation&lt;/a&gt; were published as &amp;quot;The Illusion of Life: Disney Animation&amp;quot; in 1981. These principles describe how animation can be used to immerse viewers in a believable   world.&lt;/p&gt;
&lt;p&gt;In this article I&#39;ll go through each of the 12 principles, and discuss how they might apply when making web pages. You can find the &lt;a href=&quot;http://codepen.io/collection/AxKOdY/&quot;&gt;source HTML and CSS on Codepen for them all here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;squash-and-stretch&quot; tabindex=&quot;-1&quot;&gt;Squash and stretch&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-one&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;surface&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;This is the notion that an object has a physical mass, and when it moves this mass stays the same. A ball will widen as it hits the ground when bouncing, but also get shorter as its mass is redistributed.&lt;/p&gt;
&lt;p&gt;This is most useful when creating objects that we want to be considered physical, such as people, clocks or bouncing balls.&lt;/p&gt;
&lt;p&gt;It&#39;s possible to ignore this rule when working with elements of a web page. DOM elements aren&#39;t necessarily associated with physical objects, and can grow or shrink on screen as needed. For example, a button could grow and morph into an information box, or error messages can appear and disappear.&lt;/p&gt;
&lt;p&gt;Still, the squash and stretch techniques can be used to give an object the feeling of physical mass. Even small changes in shape can create subtle but eye-catching effects.&lt;/p&gt;
&lt;h2 id=&quot;anticipation&quot; tabindex=&quot;-1&quot;&gt;Anticipation&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-two&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;surface&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Movements don&#39;t tend to happen suddenly. In real life,  motion is usually preceded by some kind of build-up, whether it&#39;s a ball beginning to roll before it falls off a table, or a person bending their knees in preparation to jump.&lt;/p&gt;
&lt;p&gt;We can use this to make our transitions and animations feel more life-like. Anticipation could be in the form of a subtle bounciness that helps people understand what is changing and keep track of the objects on-screen.&lt;/p&gt;
&lt;p&gt;For example, an element could shrink slightly before growing larger on hover; adding extra items to a list could be introduced by having other items move out of the way first.&lt;/p&gt;
&lt;h2 id=&quot;staging&quot; tabindex=&quot;-1&quot;&gt;Staging&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-three&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape b&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape c&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Staging is making sure an object is the focus of a scene, when other objects or aspects of the scene make way for where the main action is taking place. This means either placing the main action in a prominent position, or masking other elements to focus on what the user needs to see.&lt;/p&gt;
&lt;p&gt;In web terms, one approach is to use a modal overlay for certain content. Adding a dark layer over the existing page and then placing the content in front stages it and shows it as the main point of focus.&lt;/p&gt;
&lt;p&gt;Another approach is to use movement. When many objects are moving, it&#39;s hard to know which is worthy of attention. If all other movement is stopped and one object moves, even slightly, it will be much easier to spot.&lt;/p&gt;
&lt;p&gt;One technique is to make a &amp;quot;Save&amp;quot; button wobble or flash briefly to suggest to the user that they might want to save a document. With the rest of the screen held static and motionless, even subtle movement will stand out.&lt;/p&gt;
&lt;h2 id=&quot;straight-ahead-action-and-pose-to-pose&quot; tabindex=&quot;-1&quot;&gt;Straight-Ahead Action and Pose-to-Pose&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-four&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape b&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Straight-ahead action is when every frame of an animation is drawn. Pose-to-pose is when a series of keyframes are defined and the intervals filled in later, usually by an assistant.&lt;/p&gt;
&lt;p&gt;Most web animation uses pose-to-pose animation: the transition between keyframes can be handled by the browser, which interpolates the difference between each and draws in as many frames as it can to make the animation smooth.&lt;/p&gt;
&lt;p&gt;One exception to this is the &lt;code&gt;steps&lt;/code&gt; timing function. With this function, the browser &amp;quot;steps&amp;quot; through as many discrete frames as defined. This way you could draw out a series of images and have the browser display each in sequence, creating a &amp;quot;Straight Ahead Action&amp;quot; style.&lt;/p&gt;
&lt;h2 id=&quot;follow-through-and-overlapping-action&quot; tabindex=&quot;-1&quot;&gt;Follow Through and Overlapping Action&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-five&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape-container&quot;&gt;
```html
&lt;div class=&quot;shape&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Things don&#39;t always happen at the same time. When a car stops suddenly it tilts forward, with smoke from the tires and the driver inside continuing the forward motion until they are stopped or dissapate.&lt;/p&gt;
&lt;p&gt;These details are examples of follow through and overlapping action. They can be used on the web to help emphasise that something is stopping, and hasn&#39;t merely forgotten to animate. For example, an item added to a list might be slide in, proceed slightly too far, and then correct itself to the right position.&lt;/p&gt;
&lt;p&gt;To create a feeling of overlapping action, we can make elements move at a slightly different pace to each other. It&#39;s a technique used well in the iOS operating system when transitioning between views. Some buttons and elements move at different rates, and the combined effect is much more lifelike and less flat than if everything moved at the same rate. The combined movements give the viewer time to properly understand the change.&lt;/p&gt;
&lt;p&gt;In web terms this might mean stacking transitions or animations, creating effects that work at different speeds.&lt;/p&gt;
&lt;h2 id=&quot;slow-in-and-slow-out&quot; tabindex=&quot;-1&quot;&gt;Slow In and Slow Out&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-six&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Objects rarely go from a standstill to maximum speed immediately. They tend to speed up gradually and slow before stopping. Without acceleration and deceleration, movements feel robotic.&lt;/p&gt;
&lt;p&gt;In CSS terms, slow in and slow out are known as &lt;code&gt;easing&lt;/code&gt;. Easing is what is known as a timing function, a way of describing the rate of change through the course of an animation.&lt;/p&gt;
&lt;p&gt;Using timing functions, animations can start slow and speed up (ease-in), start fast and slow down (ease-out) or more complex effects using the &lt;code&gt;cubic-bezier&lt;/code&gt; timing function.&lt;/p&gt;
&lt;h2 id=&quot;arc&quot; tabindex=&quot;-1&quot;&gt;Arc&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-sevena&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape-container&quot;&gt;
```html
&lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;While objects are more lifelike when they follow the &amp;quot;Slow In and Slow Out&amp;quot;, objects rarely move in straight lines: they tend to follow curved arcs.&lt;/p&gt;
&lt;p&gt;We can achieve arcing movements with CSS in a couple of ways. One is to combine multiple animations. A bouncing ball animation, for example could be made up a ball moving up and down, while a second moves it to the right at the same time. The ball would then arc across the screen.&lt;/p&gt;
&lt;section class=&quot;demo-container principle principle-sevenb&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape b&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Another option is to rotate an element. We can adjust an object&#39;s center of rotation by setting its transform origin outside the element. When we  rotate the object, it will rotate in an arc.&lt;/p&gt;
&lt;h2 id=&quot;secondary-action&quot; tabindex=&quot;-1&quot;&gt;Secondary Action&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-eight&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape b&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape c&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;While a primary action is taking place, a secondary animation can help emphasise or augment it. This could be the swinging arms of someone walking or the tilt of their head. Or a bouncing ball kicking up a little dust.&lt;/p&gt;
&lt;p&gt;On web sites, secondary actions could see elements moving out of the way when the main focus of attention is introduced, such as dragging an item and placing it in the middle of a list.&lt;/p&gt;
&lt;h2 id=&quot;timing&quot; tabindex=&quot;-1&quot;&gt;Timing&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-nine&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape a&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;shape b&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;An animation&#39;s timing is how long it takes to complete. Timing can be used to make weighty objects look heavy in their motion, or to add character to movement.&lt;/p&gt;
&lt;p&gt;On the web this might be as simple as adjusting the &lt;code&gt;animation-duration&lt;/code&gt; or &lt;code&gt;transition-duration&lt;/code&gt; values.&lt;/p&gt;
&lt;p&gt;It&#39;s easy to let animations take longer than they need to. Adjusting timing can help get the animation out of the way of the content or interaction.&lt;/p&gt;
&lt;h2 id=&quot;exaggeration&quot; tabindex=&quot;-1&quot;&gt;Exaggeration&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-ten&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Most commonly used in cartoons, exaggeration can draw attention to certain actions and make them more dramatic. A wolf making an attempt to bite might have its jaws open wider than is normal to make the effect more scary or humorous.&lt;/p&gt;
&lt;p&gt;In a web page, objects can be scaled up and down to emphasise them and draw attention. For example when filling a form, the active section could grow while the others shrink or fade.&lt;/p&gt;
&lt;h2 id=&quot;solid-drawing&quot; tabindex=&quot;-1&quot;&gt;Solid drawing&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-eleven&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape&quot;&gt;
```html
&lt;div class=&quot;container&quot;&gt;
  &lt;span class=&quot;front&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;back&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;left&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;right&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;top&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;bottom&quot;&gt;&lt;/span&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;When animating objects in three dimensions, care should be taken to ensure they follow the rules of perspective. People are used to living in a three dimensional world, so when objects don&#39;t behave as expected they look wrong.&lt;/p&gt;
&lt;p&gt;Modern browsers have decent support for three dimensional transforms. This means that we can rotate and place objects in a scene and the browser can handle the transitions automatically.&lt;/p&gt;
&lt;h2 id=&quot;appeal&quot; tabindex=&quot;-1&quot;&gt;Appeal&lt;/h2&gt;
&lt;section class=&quot;demo-container principle principle-twelve&quot;&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
  &lt;div class=&quot;shape&quot;&gt;
```html
&lt;div class=&quot;container&quot;&gt;
  &lt;span class=&quot;item one&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;item two&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;item three&quot;&gt;&lt;/span&gt;
  &lt;span class=&quot;item four&quot;&gt;&lt;/span&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;p&gt;Appeal is the character of the artwork and how it can make us connect with the intention of the artist. Like charisma in an actor, it&#39;s the attention to detail and movement combined that creates an appealing result.&lt;/p&gt;
&lt;p&gt;Carefully crafted animations on the web can create appeal. Companies such as Stripe have made great use of animation to add credibility to their checkout process.&lt;/p&gt;
&lt;h2 id=&quot;try-it-yourself!&quot; tabindex=&quot;-1&quot;&gt;Try it yourself!&lt;/h2&gt;
&lt;p&gt;Making use of the other principles is a good way to improve animations. Animations that maintain the physical weight of objects, anticipate changes, make use of secondary actions and good timing will be valuable and helpful additions to your content.&lt;/p&gt;
&lt;p&gt;When you have the chance to add some animation to your pages, making use of one or more of these principles will make them more effective and appealing.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Mac Plus CSS</title>
    <link href="https://cssanimation.rocks/macplus/"/>
    <updated>2015-03-31T00:00:00Z</updated>
    <id>https://cssanimation.rocks/macplus/</id>
    <content type="html">&lt;p&gt;I will always remember the moment I got to use the Apple Mac Plus. In this post I will try to pay tribute to this lovely computer by creating it in CSS.&lt;/p&gt;
&lt;h2 id=&quot;retro-style&quot; tabindex=&quot;-1&quot;&gt;Retro style&lt;/h2&gt;
&lt;p&gt;Let&#39;s build (virtually) a computer. Not just any old computer, but a computer that was, for many of us, an introduction into the world of Apple. The Macintosh Plus, codename Mr. T, was first introduced in 1986 and packed a whopping 1MB of RAM and an 8 MHz processor. Aside from all that raw power, it was a seriously cute design, which made the computer more fun to use.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/macplus/mac.jpg&quot; alt=&quot;Credit: Vectronic&#39;s Apple World&quot; /&gt;&lt;/p&gt;
&lt;p&gt;In this project I will build a 3D model of the Macintosh Plus and display it in a three dimensional setting. Using CSS Keyframe animation we&#39;ll make it move on screen to show off the 3D effect better.&lt;/p&gt;
&lt;h2 id=&quot;why-use-css%3F&quot; tabindex=&quot;-1&quot;&gt;Why use CSS?&lt;/h2&gt;
&lt;p&gt;With Cascading Style Sheets are the standard way to style web page content. Everything from fonts, colors, positioning and background images is handled by CSS, and it is an essential tool for making modern web pages. It&#39;s not just for two-dimensional content. With the use of 3D transforms and positioning, you can use CSS to add depth too.&lt;/p&gt;
&lt;p&gt;Creating scenes in CSS results in smaller file sizes than images. In this example, the CSS compresses to just 4KB and the HTML less than 1KB. An equivalent image would be 100KB or more.&lt;/p&gt;
&lt;h2 id=&quot;live-demo-and-source-code&quot; tabindex=&quot;-1&quot;&gt;Live demo and source code&lt;/h2&gt;
&lt;p&gt;See the &lt;a href=&quot;https://cssanimation.rocks/mac/&quot;&gt;CSS Mac Plus online&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Full source code &lt;a href=&quot;https://github.com/donovanh/mac/archive/master.zip&quot;&gt;can be downloaded here&lt;/a&gt;, and you can view the full &lt;a href=&quot;https://github.com/donovanh/mac/blob/master/stylesheets/screen.css&quot;&gt;CSS file on Github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also follow along the various stages by looking up the &lt;code&gt;examples&lt;/code&gt; folder in &lt;a href=&quot;https://github.com/donovanh/mac/archive/master.zip&quot;&gt;the project files&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;on-prefixes&quot; tabindex=&quot;-1&quot;&gt;On Prefixes&lt;/h2&gt;
&lt;p&gt;I have omitted any CSS prefixes from the code examples to make the code easier to read. When working on this yourself make sure to include prefixes for the other browsers, such as the &lt;code&gt;webkit&lt;/code&gt;, &lt;code&gt;moz&lt;/code&gt;, &lt;code&gt;ms&lt;/code&gt;, and &lt;code&gt;o&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-stage&quot; tabindex=&quot;-1&quot;&gt;Setting the stage&lt;/h2&gt;
&lt;p&gt;When creating 3D using HTML we need a scene within which to build it. Start with a container HTML element:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a simple div with the class stage, and it acts as a container for our 3D object.&lt;/p&gt;
&lt;p&gt;To establish it as a 3D container, we set some CSS properties, &lt;code&gt;perspective&lt;/code&gt; and &lt;code&gt;perspective-origin&lt;/code&gt;. The perspective property is similar to a scene&#39;s vanishing point. The smaller the value, the shorter the vanishing point and more extreme the effect. This image shows how changing the value changes the shape on a scene:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/macplus/01-perspective.png&quot; alt=&quot;Different perspectives: 500px vs 2500px - examples/01-Perspective/index.html&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;try-it-yourself&quot; tabindex=&quot;-1&quot;&gt;Try it yourself&lt;/h3&gt;
&lt;p&gt;If you&#39;d like to have a go, look for the &lt;code&gt;screen.css&lt;/code&gt; file in the &lt;code&gt;examples/01-Perspective&lt;/code&gt; folder in the project files. You&#39;ll be able to update the perspective value and see the effect by opening the &lt;code&gt;index.html&lt;/code&gt; file from the same folder in your browser.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;perspective-origin&lt;/code&gt; property sets the viewing position. Changing it allows you to look down onto the scene from above, up from below or in from the side.&lt;/p&gt;
&lt;p&gt;In this example I&#39;ve gone for a perspective value of 1,600 pixels. The CSS looks like this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1600px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 100px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;stylesheets&lt;/code&gt; folder within the project ZIP file contains the full CSS rules for setting the various other properties on the stage, including a background, width and height.&lt;/p&gt;
&lt;h2 id=&quot;planning-the-structure&quot; tabindex=&quot;-1&quot;&gt;Planning the structure&lt;/h2&gt;
&lt;p&gt;With a stage in place we&#39;ll use some HTML elements to create the computer. Rather than try to include every last detail, we&#39;ll focus on the front detailing for the most part.&lt;/p&gt;
&lt;p&gt;The main body of the Mac is a box, tilted slightly back at an angle and sitting on a flat base.&lt;/p&gt;
&lt;p&gt;This will mean making two boxes, one tilted back a little and sitting on a flatter box. To create this effect, we&#39;ll make use of the CSS &lt;code&gt;transform&lt;/code&gt; property.&lt;/p&gt;
&lt;p&gt;If you&#39;d like to see the full HTML, it can be found in the project files within the &lt;code&gt;index.html&lt;/code&gt; file.&lt;/p&gt;
&lt;h2 id=&quot;transforms&quot; tabindex=&quot;-1&quot;&gt;Transforms&lt;/h2&gt;
&lt;p&gt;The CSS &lt;code&gt;transform&lt;/code&gt; property allows us to rotate, skew, position and even scale elements on the page. We can make use of the positioning and rotation to create our scene.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;transform&lt;/code&gt; property might look like this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.example&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You build a transform by chaining a series of statements. In this example, the example element is rotated 45 degrees around the Y-axis, and then pushed back 100px along the Z-axis.&lt;/p&gt;
&lt;p&gt;It should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/macplus/02-Transforms.png&quot; alt=&quot;Front and back panels transformed into place - examples/02-Transforms/index.html&quot; /&gt;&lt;/p&gt;
&lt;p&gt;An example of CSS transforms can be found in the &lt;code&gt;examples/02-Transforms&lt;/code&gt; folder within the project files. Two elements are positioned in the example, and their position can be changed by editing the includes &lt;code&gt;02-Transforms/css/screen.css&lt;/code&gt; file.&lt;/p&gt;
&lt;h3 id=&quot;transform-origin&quot; tabindex=&quot;-1&quot;&gt;Transform-origin&lt;/h3&gt;
&lt;p&gt;When rotating elements around the place, it’s worth keeping in mind that the transforms have an origin that can be set. The transform origin is a point referred to by specifying the X, Y and Z values. This is the default:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.default-origin&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 50% 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When building this example I kept the default but it’s worth knowing that it’s there.&lt;/p&gt;
&lt;h2 id=&quot;making-the-boxes&quot; tabindex=&quot;-1&quot;&gt;Making the boxes&lt;/h2&gt;
&lt;p&gt;We can use some transforms to set up the main body of the computer. The HTML looks like this:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;positioning animated&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;mac&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;base-front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;base-left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;base-right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;base-back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shadow&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within the stage, there&#39;s a &lt;code&gt;div&lt;/code&gt; I&#39;ll use to position the computer on the page. Within that is the Mac itself. The two boxes are themselves made up of &lt;code&gt;figure&lt;/code&gt; elements. These elements represent the sides, top, front and back of the two boxes.&lt;/p&gt;
&lt;p&gt;There is also a &lt;code&gt;figure&lt;/code&gt; to represent the shadow.&lt;/p&gt;
&lt;p&gt;This example can be found in the &lt;code&gt;examples/03-Boxes&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;The result we&#39;ll be going for looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/macplus/04-Boxes.png&quot; alt=&quot;CSS Boxes - examples/03-Boxes/index.html&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Each of the boxes are transformed into place using the CSS &lt;code&gt;transform&lt;/code&gt; property, and CSS &lt;code&gt;gradients&lt;/code&gt; are used to add depth to the scene.&lt;/p&gt;
&lt;p&gt;The CSS looks like this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.front&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 11.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9.6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #e0e0e0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5.43em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.back&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 11.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9.6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #f2f2f2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #e6e6e6 0.25em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #c2c2c2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5.45em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.top&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10.95em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9.6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #ebf0dc&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #fafafa&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #d9d9d9 0.25em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #d9d9d9 9.35em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #fafafa&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5.45em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 11.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10.9em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #ffffff&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #e0e0e0 0.25em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #b3b3b3&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5.45em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 11.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10.9em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #ffffff&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #e0e0e0 0.25em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #b3b3b3&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4.14em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.base-front&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9.6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #c2c2c2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;10.7em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.base-back&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9.6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b3b3b3&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;10.7em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.base-left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b3b3b3&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;10.7em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4.99em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.base-right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b3b3b3&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;10.7em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4.58em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.shadow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 11em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-7.4em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;20em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -20.2em 0 1.8em &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 90&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 100&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.4&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each of the figures has been given a width and height, and a CSS background gradient or color. The figures are then each positioned using the &lt;strong&gt;transform&lt;/strong&gt; property. For example, the left side is rotated 90 degrees before being translated (moved) back half the width of the computer.&lt;/p&gt;
&lt;p&gt;The front figure is translated forwards, along the Z-axis, half the length of the computer and the back is rotated 180 degrees before being translated back.&lt;/p&gt;
&lt;p&gt;For the pieces of the top box, each of the figures is rotated 5 degrees back around the X-axis. This means that the main body of the Macintosh Plus is tilted back.&lt;/p&gt;
&lt;p&gt;Finally the shadow &lt;code&gt;figure&lt;/code&gt; makes use of the CSS &lt;code&gt;box-shadow&lt;/code&gt; property to create a shadow that makes it look like the box is sitting on a flat surface.&lt;/p&gt;
&lt;h2 id=&quot;bezels&quot; tabindex=&quot;-1&quot;&gt;Bezels&lt;/h2&gt;
&lt;p&gt;A feature of this computer is the sloped edges around the front. These edges, which I&#39;ll refer to as bezels, help soften the hard corners of the box and make it look less boxy.&lt;/p&gt;
&lt;p&gt;To achieve this I added some extra elements to the front &lt;code&gt;figure&lt;/code&gt;, like so:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-top&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-bottom&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;span&lt;/code&gt; elements within the front figure each represent one of these bezels. With some styles added, they will look like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/macplus/04b-Bezels.png&quot; alt=&quot;Bezels added to front - examples/04-Bezels/index.html&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This example can be found in the &lt;code&gt;examples/04-Bezels&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;The following CSS positions each, and makes use of a border-width trick to create sloped edges.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.front .bezel-top&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.75em solid #f2f2f2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 8.6em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.front .bezel-left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em solid #d9d9d9&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.75em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.75em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.front .bezel-right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em solid #d4d4d4&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.75em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.75em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-3.62em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.front .bezel-bottom&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.75em solid #cccccc&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5em solid transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 8.65em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-10.76em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each bezel has 3 borders. For the top bezel, we set a colored border on the top. We then set two &lt;em&gt;transparent&lt;/em&gt; borders on the left and right sides. In CSS, when a border meets a border of another color, the line where they meet is diagonal. This means that the transparent borders result in diagonal edges to the colored border.&lt;/p&gt;
&lt;p&gt;This technique is applied to each of the bezels, creating the appearance of sloped edges on each.&lt;/p&gt;
&lt;p&gt;The bezels also have a transform applied to rotate and position them at the side of the front figure.&lt;/p&gt;
&lt;h2 id=&quot;more-details&quot; tabindex=&quot;-1&quot;&gt;More Details&lt;/h2&gt;
&lt;p&gt;With the main boxes of the computer in place we can add the various details that make it look like a Macintosh Plus, such as the screen, icon and disk drive.&lt;/p&gt;
&lt;p&gt;The front figure contains the following HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-top&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bezel-bottom&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;screen-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;screen&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;hello, Dave&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;sheen&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;logo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Macintosh Plus&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;floppy&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A working example can be found in the &lt;code&gt;examples/05-Completed&lt;/code&gt; folder.&lt;/p&gt;
&lt;h3 id=&quot;screen&quot; tabindex=&quot;-1&quot;&gt;Screen&lt;/h3&gt;
&lt;p&gt;The screen is made up of several elements, including a container, the screen itself and a &amp;quot;sheen&amp;quot; layer on top.&lt;/p&gt;
&lt;p&gt;The CSS for this makes use of CSS &lt;code&gt;gradients&lt;/code&gt; to make it look inset into the front of the computer and the sheen &lt;code&gt;span&lt;/code&gt; uses an almost-transparent gradient to give the screen some shininess.&lt;/p&gt;
&lt;h3 id=&quot;logo&quot; tabindex=&quot;-1&quot;&gt;Logo&lt;/h3&gt;
&lt;p&gt;The logo is made up of two parts, an image and some text. The image &lt;code&gt;span&lt;/code&gt; contains a background image of the old colorful Apple logo, and the text is positioned next to it. The CSS for these can be found in the source files.&lt;/p&gt;
&lt;p&gt;To create the right look, an embedded font is added. This uses the CSS &lt;code&gt;font-face&lt;/code&gt; property. There are many ways to do this, but perhaps the easiest is to use a service such as &lt;a href=&quot;http://www.fontsquirrel.com/tools/webfont-generator&quot;&gt;Font Squirrel&#39;s @font-face generator&lt;/a&gt; to create the following CSS:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@font-face {
  font-family: &amp;quot;apple_garamondregular&amp;quot;;
  src: url(&amp;quot;../fonts/apple_garamond-webfont.eot&amp;quot;);
  src: url(&amp;quot;../fonts/apple_garamond-webfont.eot?#iefix&amp;quot;) format(&amp;quot;embedded-opentype&amp;quot;), url(&amp;quot;../fonts/apple_garamond-webfont.woff&amp;quot;) format(&amp;quot;woff&amp;quot;), url(&amp;quot;../fonts/apple_garamond-webfont.ttf&amp;quot;) format(&amp;quot;truetype&amp;quot;), url(&amp;quot;../fonts/apple_garamond-webfont.svg#apple_garamondregular&amp;quot;) format(&amp;quot;svg&amp;quot;);
  font-weight: normal;
  font-style: normal;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Font Squirrel helps by generating the various files (eot, woff, etc) that can then be placed in the project and called in within the CSS as shown.&lt;/p&gt;
&lt;p&gt;The result is a font that closely matches the original.&lt;/p&gt;
&lt;h3 id=&quot;floppy-drive&quot; tabindex=&quot;-1&quot;&gt;Floppy drive&lt;/h3&gt;
&lt;p&gt;The floppy drive is a single element, and uses CSS borders to make it look like it&#39;s set into the front. The CSS that creates the effect looks like this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.floppy&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.2em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.8em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3d&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4.8em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 8.9em&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #555555&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.1em solid #cccccc&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.3em solid #e6e6e6&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.1em solid #f2f2f2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.3em solid #e6e6e6&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.25em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The floppy drive has a solid grey background color, and four borders. The top border is the darkest, with the bottom border being brighter to make it seem lit from above. Finally, a border-radius rounds the corners.&lt;/p&gt;
&lt;h2 id=&quot;putting-the-pieces-together&quot; tabindex=&quot;-1&quot;&gt;Putting the pieces together&lt;/h2&gt;
&lt;p&gt;Each of the pieces, when put together, look like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/macplus/05-Completed.png&quot; alt=&quot;Completed Mac Plus - examples/05-Completed/index.html&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;adding-animation&quot; tabindex=&quot;-1&quot;&gt;Adding animation&lt;/h2&gt;
&lt;p&gt;While what we have looks pretty good, we can properly show off the fact that it&#39;s a 3D object by making it move. To do this we&#39;ll make use of CSS &lt;code&gt;keyframe&lt;/code&gt; animation.&lt;/p&gt;
&lt;p&gt;In CSS, there are two types of animation. &lt;code&gt;Transitions&lt;/code&gt;, in which elements on the page animate from one style or position to another, and &lt;code&gt;keyframes&lt;/code&gt;, which represent a more complex series of animated steps.&lt;/p&gt;
&lt;p&gt;A series of &lt;code&gt;keyframes&lt;/code&gt; can be described as a series of percentages, with CSS describing each step. It could look something like this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; back-and-forth&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;40deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;40%, 50%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-40deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;90%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;40deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example the animation is called &lt;strong&gt;back-and-forth&lt;/strong&gt;, and is made up of 3 steps. It begins rotated to an angle of 40 degrees. Then by the 40% mark, is rotated to &lt;em&gt;minus&lt;/em&gt; 40 degrees. It stays at this rotation until 50%, then at 90% has returned to the original position.&lt;/p&gt;
&lt;p&gt;The browser automatically fills in the gaps by animating the properties. In this case it will animate the angle of rotation.&lt;/p&gt;
&lt;h3 id=&quot;applying-animation&quot; tabindex=&quot;-1&quot;&gt;Applying animation&lt;/h3&gt;
&lt;p&gt;To apply this animation we can use the CSS &lt;strong&gt;animation&lt;/strong&gt; tag.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;animation&lt;/code&gt; tag looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;animation: back-and-forth 14s ease-in-out infinite;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A few things are combined into one line here. It references the animation by name (&amp;quot;back-and-forth&amp;quot;), sets a &lt;code&gt;duration&lt;/code&gt; of 14 seconds, and tells the animation to repeat indefinitely. The &lt;code&gt;ease-in-out&lt;/code&gt; value refers to &lt;code&gt;easing&lt;/code&gt;, which tells the browser to have the animation start and end gradually.&lt;/p&gt;
&lt;p&gt;Applying this animation to the &amp;quot;positioning&amp;quot; div results in something like this:&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;680&quot; data-type=&quot;result&quot; data-href=&quot;HGqjp&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h2 id=&quot;what-we-learned&quot; tabindex=&quot;-1&quot;&gt;What we learned&lt;/h2&gt;
&lt;p&gt;In creating and animating a 3D object in CSS, we covered quite a few techniques. We set the &lt;code&gt;perspective&lt;/code&gt; and &lt;code&gt;perspective-origin&lt;/code&gt;. We then made use of &lt;code&gt;transforms&lt;/code&gt; to rotate, move and position elements, added &lt;code&gt;gradients&lt;/code&gt; to give a more realistic 3D effect, and used some CSS &lt;code&gt;border&lt;/code&gt; tricks to create bevels and depth. Finally we made use of &lt;code&gt;keyframes&lt;/code&gt; and CSS &lt;code&gt;animation&lt;/code&gt; to give the scene life.&lt;/p&gt;
&lt;h3 id=&quot;browser-compatibility&quot; tabindex=&quot;-1&quot;&gt;Browser compatibility&lt;/h3&gt;
&lt;p&gt;Not all browsers can yet handle CSS transforms. Internet Explorer will struggle, but there is hope that support will be &lt;a href=&quot;http://caniuse.com/transforms3d&quot;&gt;arriving in IE 11&lt;/a&gt;. All recent versions of Chrome, Safari and Firefox will do ok.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://modernizr.com/&quot;&gt;Modernizr&lt;/a&gt; provides a set of JavaScript tools to detect browser capabilities and can be used to show alternate content in cases where the browser cannot support a certain CSS property. In the example code, you&#39;ll find I&#39;ve made use of Modernizr to detect the presence of 3D transforms. In cases where they don&#39;t exist, an image is shown instead.&lt;/p&gt;
&lt;h2 id=&quot;going-forward&quot; tabindex=&quot;-1&quot;&gt;Going forward&lt;/h2&gt;
&lt;p&gt;While the example might not seem like something you&#39;d use in the average web site, the techniques can be applies to all sorts of scenarios.&lt;/p&gt;
&lt;p&gt;For example, CSS transforms can be used to add depth to page transitions, image carousels, logos and buttons, to name a few. CSS animations can be used to add more interesting movement and finesse to your transitions, and CSS gradients can add depth to pages without a need to use images.&lt;/p&gt;
&lt;script src=&quot;https://codepen.io/assets/embed/ei.js&quot;&gt; &lt;/script&gt;
</content>
  </entry><entry>
    <title>WWDC 2015</title>
    <link href="https://cssanimation.rocks/wwdc15/"/>
    <updated>2015-04-30T00:00:00Z</updated>
    <id>https://cssanimation.rocks/wwdc15/</id>
    <content type="html">&lt;p&gt;Every year Apple runs a special event for their developers called WWDC. &lt;a href=&quot;https://developer.apple.com/wwdc/&quot;&gt;WWDC&lt;/a&gt; (Apple&#39;s Worldwide Developer Conference) is a chance for iOS and OSX designers and developers to learn all about what cool stuff Apple&#39;s up to and what to expect in the new versions of the mobile and desktop software.&lt;/p&gt;
&lt;p&gt;With each year&#39;s event, they create a beautiful invitation. This year I was quite taken with the overlapping circles and shapes, and decided to have a go making it in HTML and CSS.&lt;/p&gt;
&lt;h2 id=&quot;wwdc-15-invitation&quot; tabindex=&quot;-1&quot;&gt;WWDC 15 invitation&lt;/h2&gt;
&lt;p&gt;Apple&#39;s icons often use overlapping colours and shapes, like a &lt;a href=&quot;https://cssanimation.rocks/demo/photos/&quot;&gt;iOS 7 Photos icon&lt;/a&gt;. This year the invitation to WWDC included this image:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/wwdc15/wwdc15.jpg&quot; alt=&quot;WWDC 15 invitation logo&quot; style=&quot;max-width:600px&quot; /&gt;
&lt;p&gt;It&#39;s made up of a set of overlapping, semi-transparent shapes. Perfect to recreate with some HTML and CSS.&lt;/p&gt;
&lt;h2 id=&quot;planning%3A-html&quot; tabindex=&quot;-1&quot;&gt;Planning: HTML&lt;/h2&gt;
&lt;p&gt;Taking on a complex piece like this involves a bit of planning. For this example, I broke the layout down into it&#39;s parts.&lt;/p&gt;
&lt;p&gt;The logo is made up of 3 sets of shapes. The basis is made up of 8 large circles, so I began by listing them out:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle one&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle two&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle three&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle four&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle five&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle six&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle seven&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large circle eight&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#39;m using multiple classes here so that I can write CSS that applies to all &lt;code&gt;large&lt;/code&gt; elements, and CSS that applies for all &lt;code&gt;circle&lt;/code&gt; elements, etc. The more we can reuse the CSS, the simpler it should be.&lt;/p&gt;
&lt;p&gt;We now have eight smaller shapes that sit in front and sit out at the edge of the large circles. These shapes are made up of four circles and four &amp;quot;squircles&amp;quot;, squares with a rounded edge. I&#39;ll add some HTML for them:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small circle one&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small squircle two&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small circle three&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small squircle four&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small circle five&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small squircle six&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small circle seven&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small squircle eight&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We have the eight smaller shapes listed here, with alternating &lt;code&gt;circle&lt;/code&gt; and &lt;code&gt;squircle&lt;/code&gt; classes. I&#39;ve labelled each set with numbers one through eight. This will be useful when we position the shapes and give them colours.&lt;/p&gt;
&lt;p&gt;Lastly we have two large squircles in the middle of the logo.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large squircle one&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large squircle two&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again these are of the &lt;code&gt;large&lt;/code&gt; size and the &lt;code&gt;squircle&lt;/code&gt; shape.&lt;/p&gt;
&lt;h2 id=&quot;logo-and-content&quot; tabindex=&quot;-1&quot;&gt;Logo and content&lt;/h2&gt;
&lt;p&gt;Before moving on to style this HTML we&#39;ll add some content for the central squircle.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large squircle two&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;svg&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;viewBox&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0 0 160 164&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;xmlns&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://www.w3.org/2000/svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;g&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;g&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;svg_1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
     &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;path&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;m127.805969,90.003128c0.224838,24.213104 21.241287,32.270615 21.474121,32.373459c-0.177704,0.56826 -3.358078,11.482742 -11.072464,22.756622c-6.668747,9.746841 -13.590027,19.457977 -24.493088,19.659103c-10.713348,0.197403 -14.158287,-6.353043 -26.406677,-6.353043c-12.24469,0 -16.072174,6.151901 -26.213551,6.550446c-10.52422,0.398254 -18.538303,-10.539917 -25.26247,-20.251053c-13.740021,-19.864456 -24.24024,-56.132286 -10.1411,-80.613663c7.004152,-12.157551 19.521101,-19.85622 33.10713,-20.053638c10.334515,-0.197132 20.089069,6.952717 26.406689,6.952717c6.313614,0 18.167473,-8.59832 30.628998,-7.335548c5.21682,0.217129 19.860519,2.1073 29.263641,15.871029c-0.75766,0.469692 -17.472931,10.200527 -17.291229,30.443592m-20.134499,-59.456692c5.587379,-6.7633 9.348007,-16.178439 8.322067,-25.546439c-8.053787,0.32369 -17.792625,5.36682 -23.569427,12.126399c-5.177124,5.985922 -9.711121,15.566772 -8.48777,24.749359c8.976891,0.69453 18.147476,-4.561718 23.73513,-11.329308&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;g&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;g&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;svg&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;The epicenter of change.&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;strong&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;WWDC&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;strong&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;15&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have an inline SVG image and the text from the invitation. The font used on the original image is &amp;quot;San Francisco&amp;quot;. This font isn&#39;t standard yet on OSX so for now I&#39;ll replace it with Helvetica Neue Light.&lt;/p&gt;
&lt;h2 id=&quot;styling-the-circles-and-squircles&quot; tabindex=&quot;-1&quot;&gt;Styling the circles and squircles&lt;/h2&gt;
&lt;p&gt;The first thing we want to set up is the &lt;code&gt;circle&lt;/code&gt; and &lt;code&gt;squircle&lt;/code&gt; elements.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.circle, .squircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.1em solid &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0.4&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 12.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Most of the shapes are of the larger variety so I&#39;ll style them at the larger size by default. Each of the elements uses position &lt;code&gt;absolute&lt;/code&gt; and has a light white border on top. This border might not match exactly with the invitation image but helps give the shapes a little sheen.&lt;/p&gt;
&lt;p&gt;Next we&#39;ll set styles for the large circles. Using a &lt;code&gt;border-radius&lt;/code&gt; of 50%, we can create the circle shape. We then position them using &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;top&lt;/code&gt; values.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.circle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 1em 2em &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 6.25em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 12.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 12.5em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At this point, all the circles are in the same place! But the trick here is in the &lt;code&gt;transform-origin&lt;/code&gt; value. When you rotate an object in HTML using a &lt;code&gt;transform&lt;/code&gt;, it rotates around a point called the &lt;code&gt;transform-origin&lt;/code&gt;. This point is usually in the middle (50%, 50%) of the element.&lt;/p&gt;
&lt;p&gt;In this case we&#39;ve moved this point down to the bottom of the circles. When we rotate the circles, they&#39;ll fan out into the circular shape in the logo.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/wwdc15/step1.png&quot; alt=&quot;Circles fanned out into position&quot; style=&quot;max-width:400px&quot; /&gt;
&lt;p&gt;Let&#39;s add the CSS to position each of these circles. Looking carefully at the invitation image, we can see that the circle sitting behind all the rest is on the bottom-left. With this in mind we&#39;ll make sure the first circle in the HTML is rotated around to that position.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.one&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;16&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 63&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 236&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;225deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.two&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;37&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 172&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 162&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.three&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;233&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 124&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 32&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;135deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.four&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;235&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 67&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 35&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.five&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;190&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 28&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 65&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.six&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;208&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 57&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 159&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.seven&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;150&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 32&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 198&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.eight&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;95&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 33&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 203&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each of these styles has a colour and a &lt;code&gt;transform&lt;/code&gt; to rotate it into position. This animation shows how all the circles are placed at the top-middle of the screen, then rotated into place.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cssanimation.rocks/demo/wwdc15/&quot;&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/wwdc15/circles.gif&quot; alt=&quot;Circles fanning out into position&quot; style=&quot;max-width:400px&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;With the circles in place, we can style the other shapes. Firstly, a &lt;code&gt;squircle&lt;/code&gt; is a &lt;code&gt;circle&lt;/code&gt; but with a different border radius.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.squircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 25%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we positioned the circles, we specified a rotation and a colour. Happily enough, the smaller shapes can use this same CSS too. We&#39;ll first need to give these &lt;code&gt;small&lt;/code&gt; shapes some styles of their own.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.small&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 2em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 15em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 15em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0.25em 0.5em &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0.2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We set up these shapes to be smaller and position them a greater distance up from the middle. By using the same &lt;code&gt;transform-origin&lt;/code&gt; trick, the &lt;code&gt;rotate&lt;/code&gt; transforms from earlier will put them into the correct position without need for any more CSS.&lt;/p&gt;
&lt;h3 id=&quot;small-squircles&quot; tabindex=&quot;-1&quot;&gt;Small squircles&lt;/h3&gt;
&lt;p&gt;The small &lt;code&gt;squircle&lt;/code&gt; shapes are the wrong angle. They need to be rotated a further 45 degrees.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/wwdc15/step3.png&quot; alt=&quot;Squircles in the wrong place&quot; style=&quot;max-width:400px&quot; /&gt;
&lt;p&gt;There are a couple of ways we could do this. We could add an extra element to each &lt;code&gt;squircle&lt;/code&gt; and add a transform, or we could use a &lt;a href=&quot;https://cssanimation.rocks/pseudo-elements/&quot;&gt;pseudo-element&lt;/a&gt; in the CSS. Either way is good but I thought it would be interesting to handle it in the CSS.&lt;/p&gt;
&lt;p&gt;First we remove the background, border and box shadow from the small squircles.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.small.squircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can now use the &lt;code&gt;::after&lt;/code&gt; pseudo-element to create a new squircle within each, and rotate them 45 degrees.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.small.squircle::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; red&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 25%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -0.25em 0.25em 0.5em &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0.2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.small.squircle.two::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;37&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 172&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 162&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.small.squircle.four::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;235&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 67&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 35&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.small.squircle.six::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;208&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 57&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 159&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.small.squircle.eight::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;95&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 33&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 203&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.75&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We should now have both the large circles and the smaller shapes in place.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/wwdc15/step2.png&quot; alt=&quot;Circles and squircles oh my&quot; style=&quot;max-width:400px&quot; /&gt;
&lt;h2 id=&quot;content-squircles&quot; tabindex=&quot;-1&quot;&gt;Content squircles&lt;/h2&gt;
&lt;p&gt;The last piece of the image is the two squircles that contain the content. Let&#39;s position them in the middle and give them a slightly transparent dark colour.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.large.squircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;30&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 7&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 66&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.65&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 7.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 7.5em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can then rotate the first of these squircles (the one that sits behind the squircle containing the content).&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.large.squircle.one&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://cssanimation.rocks/demo/wwdc15/&quot;&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/wwdc15/step4.png&quot; alt=&quot;Finished WWDC invitation graphic&quot; style=&quot;max-width:400px&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;adding-animation&quot; tabindex=&quot;-1&quot;&gt;Adding animation&lt;/h2&gt;
&lt;p&gt;The original invitation image is not animated, but this site is called &lt;a href=&quot;https://cssanimation.rocks/wwdc15/&quot;&gt;CSS Animation Rocks&lt;/a&gt; after all, so let&#39;s try some animation.&lt;/p&gt;
&lt;p&gt;I&#39;d like to make each of the sets of circles and squircles spin. To do this we can wrap each in a &lt;code&gt;span&lt;/code&gt; and apply an animation to the &lt;code&gt;span&lt;/code&gt; wrapper.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large-circles&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Large Circles here ... --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;small-shapes&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Small Shapes here... --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- Squircles --&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;content-squircle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;large squircle one&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First we position these &lt;code&gt;span&lt;/code&gt; elements so that they don&#39;t break the layout.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;span {
  display: block;
  height: 20em;
  left: calc(50% - 10em);
  position: absolute;
  top: calc(50% - 10em);
  width: 20em;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This places the &lt;code&gt;span&lt;/code&gt; wrappers in the middle of the page.&lt;/p&gt;
&lt;p&gt;Next we will apply animations to each of these three &lt;code&gt;span&lt;/code&gt; elements.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.large-circles&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin 10s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.small-shapes&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin 30s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.content-squircle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin 20s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;re using the same set of keyframes each time, but changing the &lt;code&gt;animation-duration&lt;/code&gt; of each. I&#39;ve chosen 10 seconds, 20 seconds and 30 seconds so that they&#39;ll line up every minute.&lt;/p&gt;
&lt;p&gt;With the &lt;code&gt;animation&lt;/code&gt; property in place, let&#39;s put together the &lt;code&gt;keyframes&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; spin&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This starts with zero rotation and finishes the animation having rotated around 360 degrees. &lt;a href=&quot;https://cssanimation.rocks/demo/wwdc15/&quot;&gt;See it in action in this demo&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;reusing-css&quot; tabindex=&quot;-1&quot;&gt;Reusing CSS&lt;/h2&gt;
&lt;p&gt;This is a fun experiment in creating overlapping shapes using CSS but one thing that I found most helpful was the way the CSS was reused in some places. Rotating both the circles and the smaller shapes was handled by the same CSS, and the animations all used one set of keyframes. This can be a good way to keep your CSS files small and make sure they load quickly.&lt;/p&gt;
&lt;h2 id=&quot;prefixes&quot; tabindex=&quot;-1&quot;&gt;Prefixes&lt;/h2&gt;
&lt;p&gt;When creating this example, I used &lt;a href=&quot;https://github.com/postcss/autoprefixer&quot;&gt;autoprefixer&lt;/a&gt; to avoid having to think about adding browser prefixes. Do keep this in mind if you&#39;re using &lt;code&gt;transitions&lt;/code&gt;, &lt;code&gt;animations&lt;/code&gt; or &lt;code&gt;transforms&lt;/code&gt; in production.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Buffer&#39;s loading animation</title>
    <link href="https://cssanimation.rocks/buffer/"/>
    <updated>2015-05-22T00:00:00Z</updated>
    <id>https://cssanimation.rocks/buffer/</id>
    <content type="html">&lt;p&gt;I love finding examples of subtle animation in websites. Recently, when I was logging into &lt;a href=&quot;https://bufferapp.com/&quot;&gt;Buffer&lt;/a&gt;, I noticed a nice loading effect in their logo. Here&#39;s how to recreate it using SVG and CSS.&lt;/p&gt;
&lt;h2 id=&quot;indicating-activity&quot; tabindex=&quot;-1&quot;&gt;Indicating activity&lt;/h2&gt;
&lt;p&gt;When something takes longer than expected, it&#39;s a nice idea to include some visual feedback to tell your visitor that something is happening. One way is to have a subtle animation, or loading animation, on the page. Buffer&#39;s approach is to animate their logo:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/buffer/buffer.gif&quot; alt=&quot;Buffer loading animation&quot; style=&quot;max-width: 272px&quot; /&gt;
&lt;p&gt;The animation is achieved using an animated GIF file.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/buffer/buffer-loading.gif&quot; alt=&quot;Buffer icon gif&quot; style=&quot;max-width: 26px; border: 1em solid #fff;&quot; /&gt;
&lt;p&gt;When the loading is complete, the animated GIF is swapped out for a static PNG version of the logo.&lt;/p&gt;
&lt;p&gt;It can be tricky to cleanly swap an animated GIF with a static image, and in this case we see a slight &amp;quot;jump&amp;quot; as the two are switched.&lt;/p&gt;
&lt;p&gt;Let&#39;s see if we can get around this by creating the animation and finished state using CSS.&lt;/p&gt;
&lt;h2 id=&quot;why-use-css%3F&quot; tabindex=&quot;-1&quot;&gt;Why use CSS?&lt;/h2&gt;
&lt;p&gt;There are some significant advantages of using CSS instead of animated GIF files. The main advantage is size. While the animated GIF in use here is pretty small, at a mere 6Kb, the CSS needed to create a similar effect is a fraction of that. (The entire HTML and CSS on the demo page is 2.8Kb, including the heading and button styles).&lt;/p&gt;
&lt;p&gt;CSS gives us the option to do more, while an animated GIF cannot be edited once created. Having said that, animated GIFs can be any animation at all, so may be suitable for more complex animation that couldn&#39;t be handled in CSS. For an example, see how the &lt;a href=&quot;http://cssanimation.rocks/twitter-fave/&quot;&gt;Twitter fav animation&lt;/a&gt; uses an image sprite to get around this.&lt;/p&gt;
&lt;p&gt;Another advantage to using CSS is that it&#39;s resolution independent. We can scale it up to any size and it&#39;ll still look clear. To make the most of this, we can use an SVG image.&lt;/p&gt;
&lt;h2 id=&quot;creating-an-svg-logo&quot; tabindex=&quot;-1&quot;&gt;Creating an SVG logo&lt;/h2&gt;
&lt;p&gt;Before creating an SVG I spent a while trying to create the Buffer logo using CSS. A similar effect can be seen on the &lt;a href=&quot;https://get.fabric.io/&quot;&gt;Fabric&lt;/a&gt; landing page, with 3 squares animating into place using CSS. Unfortunately the more subtle details in the Buffer layers meant it was too tricky, so I turned to SVG instead.&lt;/p&gt;
&lt;p&gt;SVG (Scaleable Vector Graphics) is a type of vector image file. The files are made up of a series of paths, are infinitely scaleable and can be very efficient. There are various tools used to create them, including Sketch, Affinity Designer, and Adobe Illustrator.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/buffer/image_trace.png&quot; alt=&quot;Tracing the image using illustrator&quot; /&gt;
&lt;p&gt;In this case, I traced the PNG logo in Illustrator and tidied it up to create an SVG. The result is nice and efficient. Here it is in full:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;svg&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100%&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100%&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;viewBox&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0 0 313.3 321.4&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;enable-background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;new 0 0 313.3 321.4&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;xml:&lt;/span&gt;space&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;preserve&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;path&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;layer layer1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;path&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;layer layer2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;path&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;layer layer3&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;svg&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&#39;s the result:&lt;/p&gt;
&lt;div class=&quot;demo-container non-grey&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://cssanimation.rocks/images/posts/buffer/buffer_icon.svg&quot;&gt;Download this SVG here&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;styling-svg-layers&quot; tabindex=&quot;-1&quot;&gt;Styling SVG layers&lt;/h2&gt;
&lt;p&gt;You may have noticed the &lt;code&gt;class&lt;/code&gt; parts of the SVG. I added these so that I can style the SVG using CSS.&lt;/p&gt;
&lt;p&gt;There are some attributes we can style with CSS, including stroke, fill and even adding CSS filters. For this example I&#39;ll be working on the &lt;code&gt;fill&lt;/code&gt; property, which is like &lt;code&gt;background-color&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;One thing worth noting: When we reference SVG images using the &lt;code&gt;img&lt;/code&gt; tag, we can&#39;t style the contents of the SVG with CSS. In this example I&#39;m including the text of the SVG file directly in the source. This allows the CSS to work on it.&lt;/p&gt;
&lt;p&gt;We can give the layers the Buffer grey colour using this CSS:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.layer&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4b4b4b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;demo-container&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer&quot; d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer&quot; d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer&quot; d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;animating&quot; tabindex=&quot;-1&quot;&gt;Animating&lt;/h2&gt;
&lt;p&gt;We can use &lt;code&gt;keyframe&lt;/code&gt; animation to create the loading animation effect. When planning out animations like this, I like to turn to pen and paper and structure the animation. The goal is to have 3 animations, all looping in sync.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/buffer/timeline.jpg&quot; alt=&quot;Timeline of the animations on the layers&quot; /&gt;
&lt;p&gt;Keyframes describe animations as a series of steps from 0% to 100%. To illustrate this, I&#39;ve marked out the areas where the layers need to be &amp;quot;on&amp;quot; to create a similar effect to the animated GIF.&lt;/p&gt;
&lt;p&gt;We&#39;ll create three sets of keyframes, one for each of the layers:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; layer1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 65%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b2b2b2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;75%, 82%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4b4b4b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;92%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b2b2b2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; layer2&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 40%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b2b2b2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;50%, 86%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4b4b4b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;96%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b2b2b2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; layer3&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 15%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b2b2b2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;25%, 90%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4b4b4b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #b2b2b2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each layer begins with the lighter grey (#b2b2b2) and then animates to the darker grey (#4b4b4b). I&#39;ve also staggered the end of each animation so that it looks like the darker colour descends from the top to the bottom before repeating.&lt;/p&gt;
&lt;p&gt;With the keyframes in place, we need to apply them to the layers.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.layer&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.layer1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; layer1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.layer2&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; layer2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.layer3&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; layer3&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This applies each of those three sets of keyframes to the correct layer.&lt;/p&gt;
&lt;section class=&quot;demo-container animated&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer layer1&quot; d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer2&quot; d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer3&quot; d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/section&gt;
&lt;h2 id=&quot;scaling-it-down&quot; tabindex=&quot;-1&quot;&gt;Scaling it down&lt;/h2&gt;
&lt;p&gt;Let&#39;s see how it sits alongside the real logo:&lt;/p&gt;
&lt;section class=&quot;demo-container finished&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 363.1 74.2&quot; style=&quot;enable-background:new 0 0 363.1 74.2;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer&quot; d=&quot;M102,71.3c0-3.5,0-6.6,0-9.7c0-18.2,0.2-36.3-0.1-54.5c-0.1-4.7,1.3-6.3,5.9-5.8c2.3,0.3,4.6,0,7.5,0c0,8.4,0,16.2,0,23.1
  c5.8-1.7,11.3-4.3,16.9-4.6c9.4-0.5,16.4,5.6,19.6,15.5c2.5,7.7,2.4,15.5-0.4,23c-5.5,14.7-21.5,18.9-33.7,9.1
  c-0.5-0.4-1-0.7-1.9-1.3c-0.2,1.9-0.4,3.3-0.6,5.1C111,71.3,106.9,71.3,102,71.3z M114.6,46.6c0.8,3.6,0.7,7.8,2.7,10.6
  c3.2,4.4,10.7,5.1,15.5,2.5c5.1-2.7,7.9-9.5,6.7-16.4c-1-6.2-4.8-10.5-10.1-11.5C120,30.2,115.4,35,114.6,46.6z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer&quot; d=&quot;M291.7,50.4c0.9,12,12.1,14.8,27.7,7.5c1.7,2.5,3.5,5.1,5.2,7.5c-8.1,8.7-26,10-36.7,2.8c-10.2-6.9-13.9-21.3-8.5-33.5
  c5.2-11.6,18.2-17.7,30.8-14.3c12,3.2,19.3,15,17.9,29.9C316.1,50.4,303.9,50.4,291.7,50.4z M315.5,41.2c-1.3-7.5-6.1-11.4-12.8-11
  c-6.4,0.3-10.7,4.4-11.3,11C299.3,41.2,307.2,41.2,315.5,41.2z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer&quot; d=&quot;M193.5,21.1c4.7,0,8.5,0,12.7,0c0,16.7,0,33.2,0,50.2c-3.9,0-8,0-12.3,0c-0.2-1.5-0.4-3.1-0.8-5.4c-5.7,4.7-11.7,7.4-18.9,7
  c-8.9-0.5-14.4-4.9-14.7-13.7c-0.4-12.5-0.1-24.9-0.1-37.8c4.2,0,8.3,0,13.1,0c0,5.5,0,11.1,0,16.7c0,4.2,0.1,8.3,0,12.5
  c-0.1,4.7,0.8,8.7,6.1,10.1c5,1.3,12.1-1,14.2-5c0.7-1.4,0.7-3.2,0.7-4.8C193.5,41.1,193.5,31.4,193.5,21.1z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer&quot; d=&quot;M248.9,5.3c-1.5,2.4-3,4.6-4.3,6.8c-10.3-2.1-13.1-0.1-11.8,8.6c3,0.2,6.1,0.3,9.4,0.5c0,3.7,0,7.2,0,11
  c-3.1,0.2-6.2,0.4-10,0.6c0,12.9,0,25.6,0,38.5c-4.8,0-8.8,0-13.5,0c0-13,0-25.7,0-38.6c-2.8-0.2-5.1-0.4-7.8-0.6
  c0-3.7,0-7.2,0-11.1c2.5-0.2,4.9-0.3,7.6-0.5c0.1-8.4,2-15.8,10.7-19.1C235.5-0.8,243.4,0.6,248.9,5.3z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer&quot; d=&quot;M253.1,32.9c-3.3-0.2-5.6-0.4-8.1-0.6c0-3.7,0-7.1,0-11c2.4-0.2,4.8-0.3,7.8-0.6c0.2-8.8,2.3-16.9,12-19.5
  c6.5-1.7,12.8-1,18.5,3.8c-1.6,2.6-3.1,5-4.5,7.2c-9.4-2.7-12.7-0.5-11.9,8.5c3,0,6.1,0,9.5,0c0,4.1,0,7.6,0,11.5
  c-3.2,0.2-6.1,0.3-9.7,0.5c0,12.8,0,25.5,0,38.5c-4.7,0-8.7,0-13.5,0C253.1,58.6,253.1,45.9,253.1,32.9z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer&quot; d=&quot;M347.4,71c-1,0.4-1.3,0.6-1.6,0.6c-11.6,0.9-11.6,0.9-11.6-10.7c0-11.3,0-22.6,0-33.9c0-1.8,0-3.6,0-5.7c4.6,0,8.7,0,13,0
  c0.1,1.7,0.3,3.4,0.4,4.7c4.9-2.4,9.8-4.8,15.6-7.6c0,5.5,0,9.4,0,13.6c-1.7,0.1-3.5,0.1-5.3,0.5c-9,2.1-11,4-10.6,12
  C347.8,53.3,347.4,62.1,347.4,71z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer layer1&quot; d=&quot;M36.2,0c0.9,0,1.8,0.4,2.6,0.7c10.5,4.9,21,9.8,31.6,14.7c0.8,0.4,1.8,0.5,1.9,1.6c0,1.2-1.1,1.3-1.8,1.6
  c-10.6,5-21.2,9.9-31.8,14.8c-1.7,0.8-3.4,0.8-5.1,0c-10.8-5-21.5-10-32.3-15.1c-0.5-0.3-1.3-0.9-1.2-1.4c0-0.5,0.7-1.1,1.3-1.4
  C12.1,10.7,22.9,5.6,33.6,0.6C34.4,0.3,35.7,0,36.2,0z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer layer2&quot; d=&quot;M36.1,54.2c-0.7,0-1.8-0.4-2.6-0.8c-10.7-5-21.5-10-32.2-15c-0.6-0.3-1.3-0.9-1.3-1.3c0.1-0.5,0.7-1.2,1.3-1.5
  c1.7-0.9,3.5-1.7,5.3-2.5c1.8-0.8,3.6-0.8,5.4,0c7,3.3,14.1,6.5,21.1,9.9c2,0.9,3.9,0.9,5.9,0c7-3.3,14.1-6.6,21.1-9.9
  c1.8-0.8,3.6-0.9,5.3,0c1.9,0.9,3.8,1.7,5.6,2.7c0.5,0.2,1.1,0.9,1.1,1.2c0,0.5-0.6,1.1-1.1,1.4c-10.8,5.1-21.6,10.1-32.5,15.2
  C37.9,53.9,36.9,54.2,36.1,54.2z&quot;&gt;&lt;/path&gt;
&lt;path class=&quot;layer layer3&quot; d=&quot;M36.2,74.2c-1.1,0-2.1-0.5-3.1-1c-10.4-4.8-20.8-9.7-31.2-14.6C1.1,58.3,0,58.2,0,57c0-1.2,0.9-1.3,1.6-1.6
  c3.2-1.5,3.4-1.5,5-2.3c1.9-0.9,3.7-0.9,5.6,0c6.9,3.2,13.8,6.4,20.7,9.7c2.2,1.1,4.3,1.1,6.5,0c6.9-3.3,13.8-6.4,20.7-9.7
  c1.9-0.9,3.8-0.9,5.7,0c1.8,0.9,3.6,1.7,5.4,2.6c0.5,0.2,1.1,0.8,1.1,1.2c0,0.6-0.6,1.1-1.1,1.4c-7.4,3.5-14.9,7-22.3,10.5
    c-3.2,1.5-6.4,3-9.6,4.5C38.2,73.7,37.3,74.2,36.2,74.2z&quot;&gt;&lt;/path&gt;
```
  &lt;/svg&gt;
&lt;/section&gt;
&lt;p&gt;Pretty sweet!&lt;/p&gt;
&lt;p&gt;The result is small (~3Kb in total including CSS, using Gzip), scales to retina and beyond, and can be easily changed in CSS if needed. The animation can also be stopped using a little JavaScript rather than swapping out another image. See this in action in &lt;a href=&quot;https://cssanimation.rocks/demo/buffer&quot;&gt;the demo&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;taking-it-further&quot; tabindex=&quot;-1&quot;&gt;Taking it further&lt;/h2&gt;
&lt;p&gt;Since we&#39;ve used CSS to set up the animation, we can try variations without changing the SVG file.&lt;/p&gt;
&lt;section class=&quot;demo-container multiple variation1&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer layer1&quot; d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer2&quot; d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer3&quot; d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-container multiple variation2&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer layer1&quot; d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer2&quot; d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer3&quot; d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-container multiple variation3&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer layer1&quot; d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer2&quot; d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer3&quot; d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-container multiple variation4&quot;&gt;
  &lt;svg width=&quot;100%&quot; height=&quot;100%&quot; x=&quot;0px&quot; y=&quot;0px&quot; viewBox=&quot;0 0 313.3 321.4&quot; style=&quot;enable-background:new 0 0 313.3 321.4;&quot; xml:space=&quot;preserve&quot;&gt;
```css
&lt;path class=&quot;layer layer1&quot; d=&quot;M157.1,0c3.8,0,7.9,1.5,11.4,3.2c45.6,21.1,91.2,42.4,136.7,63.8c3.3,1.5,8,2.1,8.1,7c0.1,5-4.7,5.6-7.9,7.1
```
  c-45.8,21.5-91.7,42.9-137.6,64.3c-7.4,3.4-14.8,3.5-22.2,0C99,123.6,52.3,101.9,5.8,80c-2.4-1.1-5.4-4-5.4-6c0-2,3.1-4.8,5.5-5.9
  C52.4,46.2,99.1,24.4,145.8,2.8C149.1,1.2,154.5,0,157.1,0z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer2&quot; d=&quot;M156.6,235c-3.1,0-7.7-1.7-11.3-3.3c-46.5-21.6-93-43.3-139.4-65.1c-2.4-1.1-5.8-4.1-5.6-5.8c0.3-2.4,3.2-5,5.7-6.3
```
  c7.5-4,15.3-7.3,23-10.9c7.9-3.7,15.7-3.6,23.6,0.1c30.4,14.3,61,28.4,91.4,42.7c8.6,4.1,16.8,4,25.4-0.1
  c30.4-14.3,60.9-28.4,91.4-42.7c7.7-3.6,15.4-3.7,23.1-0.1c8.2,3.8,16.4,7.4,24.4,11.5c2.1,1.1,4.9,3.7,4.7,5.4
  c-0.2,2.1-2.7,4.8-4.9,5.9c-46.8,22.1-93.7,44-140.7,65.8C164.2,233.5,159.9,235,156.6,235z&quot;&gt;&lt;/path&gt;
```css
&lt;path class=&quot;layer layer3&quot; d=&quot;M156.8,321.4c-4.6,0-9.3-2.3-13.4-4.2c-45.2-20.9-90.3-42-135.4-63.1c-3.3-1.5-8-2.1-8-7.1c0-5,3.8-5.5,7-7.1
```
  c13.9-6.5,14.9-6.5,21.8-9.8c8-3.8,16-3.7,24.1,0.1c29.9,14,59.8,27.7,89.6,41.9c9.6,4.6,18.5,4.7,28.2,0.1 c29.8-14.2,59.8-27.9,89.6-41.9c8.2-3.9,16.3-4,24.5,0c7.8,3.8,15.8,7.2,23.5,11.1c2.1,1.1,4.8,3.3,4.8,5.4
  c-0.1,2.4-2.7,4.8-4.9,5.9c-32.2,15.3-64.5,30.3-96.8,45.4c-13.9,6.5-27.7,13.1-41.7,19.3C165.7,319.2,161.5,321.4,156.8,321.4z&quot;&gt;&lt;/path&gt;
  &lt;/svg&gt;
&lt;/section&gt;
&lt;h2 id=&quot;download-the-files&quot; tabindex=&quot;-1&quot;&gt;Download the files&lt;/h2&gt;
&lt;p&gt;You can &lt;a href=&quot;https://cssanimation.rocks/demo/buffer/buffer_icon_svg.zip&quot;&gt;download the finished HTML and CSS here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;browser-compatibility&quot; tabindex=&quot;-1&quot;&gt;Browser compatibility&lt;/h2&gt;
&lt;p&gt;Thankfully SVG has become mainstream. A site I often check for these things is &lt;a href=&quot;http://caniuse.com/#feat=svg&quot;&gt;CanIUse.com&lt;/a&gt;. Here we see decent support for SVG across all modern browsers. However if you want to make sure your visitors in older browsers have a good experience, I&#39;d recommend using &lt;a href=&quot;http://modernizr.com/&quot;&gt;Modernizr&lt;/a&gt; and serving a static image.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Portal CSS</title>
    <link href="https://cssanimation.rocks/portal/"/>
    <updated>2015-07-08T00:00:00Z</updated>
    <id>https://cssanimation.rocks/portal/</id>
    <content type="html">&lt;p&gt;You don&#39;t need JavaScript to create impressive 3D projects in the web browser. In this post I will show how to create and animate a Portal-inspired scene using only CSS.&lt;/p&gt;
&lt;p&gt;See the &lt;a href=&quot;http://hop.ie/portal/&quot;&gt;online Portal CSS demo&lt;/a&gt;, and download the &lt;a href=&quot;https://github.com/donovanh/portal&quot;&gt;source on Github&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;portal-orientation-video-no.-1&quot; tabindex=&quot;-1&quot;&gt;Portal Orientation Video No. 1&lt;/h2&gt;
&lt;p&gt;As an example to show the various stages of creating, styling and then animating a 3D scene, this post will aim to recreate a scene from the &lt;a href=&quot;http://www.youtube.com/watch?v=gr_9Fw_gC4I&quot;&gt;Portal Training Video&lt;/a&gt;. In particular, the stylised, cartoony look of the first part of the video in which a silhouetted character jumps through a portal and emerges from the other side. This is the original video:&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
  &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/V5paXrfkYmI?modestbranding=1&amp;cc_load_policy=0&amp;iv_load_policy=3&amp;vq=hd720&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;This video blew my mind when it was first released. Portal (which was developed from &lt;a href=&quot;http://en.wikipedia.org/wiki/Narbacular_Drop&quot;&gt;Narbacular Drop&lt;/a&gt;) introduced a fun twist on the 3D platform genre.&lt;/p&gt;
&lt;p&gt;The isometric, cartoony graphics in the introduction video are very different from the game yet manage to capture some of it&#39;s style. In this post I will see if this cartoony style can be reproduced using nothing but HTML and CSS.&lt;/p&gt;
&lt;p&gt;In particular, this is the scene that will be created:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/video.jpg&quot; alt=&quot;Portal video screenshot&quot; /&gt;
&lt;h3 id=&quot;a-quick-note-on-prefixes&quot; tabindex=&quot;-1&quot;&gt;A quick note on prefixes&lt;/h3&gt;
&lt;p&gt;I&#39;ve removed the prefixed versions of rules in the following CSS. I would recommend either using something like &lt;a href=&quot;http://leaverou.github.io/prefixfree/&quot;&gt;prefix free&lt;/a&gt; or &lt;a href=&quot;http://sass-lang.com/&quot;&gt;SASS&lt;/a&gt; to manage these for you. Otherwise, be aware that most browser prefixes will need to applied. Full versions of the CSS and SASS can be found &lt;a href=&quot;https://github.com/donovanh/portal&quot;&gt;on Github&lt;/a&gt; along with the HTML.&lt;/p&gt;
&lt;h3 id=&quot;there&#39;s-science-to-be-done&quot; tabindex=&quot;-1&quot;&gt;There&#39;s science to be done&lt;/h3&gt;
&lt;p&gt;The following project has been developed and tested primarily in Chrome. It uses CSS that won&#39;t work properly in Internet Explorer. It covers some interesting 3D CSS techniques that while they aren&#39;t yet mainstream, can prove useful in other front-end development.&lt;/p&gt;
&lt;h2 id=&quot;getting-started&quot; tabindex=&quot;-1&quot;&gt;Getting started&lt;/h2&gt;
&lt;p&gt;We need to set a scene in which we can build our 3D creation. To do this we&#39;ll need to use an HTML element and give it the needed properties that tell the browser to expect 3D content within it. Start with some HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;article&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;...&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;article&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this case the container is an &lt;code&gt;article&lt;/code&gt; tag. In HTML5, &lt;em&gt;article&lt;/em&gt; represents a standalone piece of content that could be reproduced elsewhere and still make sense.&lt;/p&gt;
&lt;p&gt;The first property to apply is &lt;a href=&quot;http://docs.webplatform.org/wiki/css/properties/perspective&quot;&gt;perspective&lt;/a&gt;. This property takes a value in pixels, and represents the depth of the 3D scene. A smaller value will produce a more dramatic effect, and it&#39;s usual to set it somewhere betweeh 800 and 1,200 pixels.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/perspective.gif&quot; alt=&quot;Alternating between a perspective value of 900 pixels and 2000 pixels&quot; class=&quot;bordered centered&quot; /&gt;
&lt;p&gt;For this scene to feel like it&#39;s a large room, we will set the perspective value quite high at 2,600 pixels. Ignoring the various browser prefixes, we use the following:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;article.container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2600px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;vanishing-point&quot; tabindex=&quot;-1&quot;&gt;Vanishing point&lt;/h3&gt;
&lt;p&gt;The container for the scene has a depth, so the next step is to determine the viewing angle. By adjusting the &lt;a href=&quot;http://docs.webplatform.org/wiki/css/properties/perspective-origin&quot;&gt;perspective-origin&lt;/a&gt; property, we can establish the scene&#39;s vanishing point, and determine whether we&#39;re looking down at the object or from the side.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% -1400px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;perspective-origin&lt;/code&gt; property takes two values, a horizontal and a vertical offset. In this case we&#39;re setting it half-way across the scene, and 1,400 pixels up. This will result in our point of view being above the object, looking down.&lt;/p&gt;
&lt;p&gt;To determine these values, I adjusted the value in the Chrome web inspector panel and judged it by eye. When setting up your scene, your value might be higher or lower than this. It will depend on the effect you want to convey. Also keep in mind that this value can be animated, creating some interesting perspective-change effects.&lt;/p&gt;
&lt;h3 id=&quot;no-vectors%2C-victor&quot; tabindex=&quot;-1&quot;&gt;No vectors, Victor&lt;/h3&gt;
&lt;p&gt;The objects we position in HTML are normal HTML elements. They have a width, height, and are rectangular. This means that as you build a 3D object, you place each rectangle in place. This differs from some other methods that involve describing points and lines to create shapes. It also means that there aren&#39;t as many primatives, such as circles or cubes, to draw upon.&lt;/p&gt;
&lt;p&gt;The HTML elements are placed within the 3D scene using the &lt;code&gt;transform&lt;/code&gt; property.&lt;/p&gt;
&lt;h3 id=&quot;transforming&quot; tabindex=&quot;-1&quot;&gt;Transforming&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;transform&lt;/code&gt; property consists of a series of adjustments to the HTML element. These adjustments can take the form of &lt;code&gt;translate&lt;/code&gt; to move the element, &lt;code&gt;rotate&lt;/code&gt; to adjust it&#39;s angle, &lt;code&gt;skew&lt;/code&gt; and even &lt;code&gt;scale&lt;/code&gt;. Each of these can be stacked to create more complex transforms, for example:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.example&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This rule will rotate an element 45 degrees around the Y axis, then move it back 100 pixels on the Z axis. The effect would look like this:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/transform.png&quot; alt=&quot;A transform in action&quot; class=&quot;bordered centered&quot; /&gt;
&lt;h3 id=&quot;transform-origin-property&quot; tabindex=&quot;-1&quot;&gt;Transform origin property&lt;/h3&gt;
&lt;p&gt;When rotating elements around the place, it&#39;s worth keeping in mind that the transforms have an origin that can be set. The &lt;a href=&quot;http://docs.webplatform.org/wiki/css/properties/transform-origin&quot;&gt;transform origin&lt;/a&gt; is a point referred to by specifying the X, Y and Z values. This is the default:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.default-origin&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 50% 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When building this example I kept the default but it&#39;s worth knowing that it&#39;s there.&lt;/p&gt;
&lt;h2 id=&quot;let&#39;s-build&quot; tabindex=&quot;-1&quot;&gt;Let&#39;s build&lt;/h2&gt;
&lt;p&gt;With the scene set, we can start putting together our 3D masterpiece. When beginning to build 3D objects with HTML and CSS, it&#39;s worth taking a moment to understand how this approach differs from other 3D software.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shadow&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back-left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back-right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;platform-left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;platform-right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;pit-left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;pit-right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;pit-back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above includes a &lt;em&gt;stage&lt;/em&gt; section, which we will be using to contain all the elements. A set of divs within the stage section form the main parts of the structure. They take the form of back pieces, platforms, the sides of the pit, and a shadow to place underneath them.&lt;/p&gt;
&lt;p&gt;When I started building this scene, I tried to place the walls directly onto the stage, rotating it and adjusting its position. However since the scene is being viewed from an isometric angle, an easier approach is to place the parts of the scene and then rotate the entire scene 45 degrees at once.&lt;/p&gt;
&lt;p&gt;With that in mind, the HTML elements are transformed into place according to the following sketch:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/sketch.png&quot; alt=&quot;Plan view of the scene&quot; class=&quot;centered&quot; /&gt;
&lt;p&gt;As the sketch shows, the &lt;em&gt;back-left&lt;/em&gt; piece is aligned to the left, but the &lt;em&gt;back-right&lt;/em&gt; piece is right in front of the viewer. To adjust for this, we&#39;ll rotate the entire stage 45 degrees later.&lt;/p&gt;
&lt;p&gt;Before applying transforms however, we need to give the divs some shared properties:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage div&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; preserve-3d&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each div will be positioned absolutely, and the &lt;code&gt;transform-style&lt;/code&gt; property to instruct the browser that 3D transforms are to be applied in relation to the perspective we set earlier.&lt;/p&gt;
&lt;p&gt;With this done we can start positioning divs:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .back-left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #6b522b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #574625&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #8a683d&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-256px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 500px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above rules describe a width of 500 pixels, which is the side length of our 3D scene, a height of 120 pixels and a light brown background colour. The div is then rotated 90 degrees and pushed back along the X axis. The div has a 6 pixel border applied to create the illusion of depth.&lt;/p&gt;
&lt;p&gt;A similar transform is applied to the &lt;em&gt;back-right&lt;/em&gt; div:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .back-right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #9c7442&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #78552c&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #b5854a&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;253px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;3px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 446px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This div is a little smaller, as it looks like the room in the original Portal video is not quite square.&lt;/p&gt;
&lt;p&gt;Next, add in some platforms and the sides of the pit:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .platform-left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #bcb3a8&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #857964&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 220px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;396px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;253px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-13px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 446px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .platform-right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #bcb3a8&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #847660&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #554c3d&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 164px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;88px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;253px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-41px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 446px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .pit-left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4d4233&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 800px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;254px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 125px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 285px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 447px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .pit-right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #847660&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 800px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -1400px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;254px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 125px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 173px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 451px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .pit-back&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #6b522b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 220px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-200px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 87px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 168px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 170px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The end result of all this should be a scene that looks like this:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/layout01.png&quot; alt=&quot;Initial layout of the stage divs&quot; /&gt;
&lt;p&gt;It doesn&#39;t look right yet. We need to rotate the entire scene to see it properly. Add a &lt;code&gt;transform&lt;/code&gt; to the &lt;em&gt;scene&lt;/em&gt; section:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; preserve-3d&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-45deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 460px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result should look more like this:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/layout02.png&quot; alt=&quot;Initial layout rotated to show the stage properly&quot; /&gt;
&lt;p&gt;You may notice that the borders create a nice depth effect, particularly at the corners, where the different coloured borders meet with a 45 degree angle. Since the scene we&#39;re building is to be viewed at 45 degrees, this effect works to our advantage in most cases. A few of the corners don&#39;t quite look right, but considering how straightforward the borders are to apply, and the lack of images, I feel this is a reasonable compromise.&lt;/p&gt;
&lt;h3 id=&quot;in-the-shade&quot; tabindex=&quot;-1&quot;&gt;In the shade&lt;/h3&gt;
&lt;p&gt;The video features a nice shadow beneath the platforms. We can reproduce this using the CSS &lt;code&gt;box-shadow&lt;/code&gt; property.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .shadow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transparent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -600px 0 50px #afa79f&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 550px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-166px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;550px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 550px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The rules above add a box shadow to the &lt;em&gt;shadow&lt;/em&gt; div, which is itself transparent. The box shadow is offset by 600 pixels so that the actual &lt;em&gt;shadow&lt;/em&gt; div doesn&#39;t get in the way of the shadow. The whole lot is rotated and positioned off-stage, so that only the shadow part is visible on the stage. The result should be something like this:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/layout03.png&quot; alt=&quot;Initial layout with a shadow&quot; /&gt;
&lt;h2 id=&quot;red-vs-blue&quot; tabindex=&quot;-1&quot;&gt;Red VS Blue&lt;/h2&gt;
&lt;p&gt;Next up we need to add some decoration and the glowing portals.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/portal.png&quot; alt=&quot;Red portal&quot; /&gt;
&lt;p&gt;The HTML needed for the two portals is simple enough:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;portal red&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;portal blue&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is a &lt;code&gt;div&lt;/code&gt; for each of the two portals, one red and the other blue. They both have a similar style, with gradients used to create glowing effect. Since they are only one HTML element, the CSS includes a pseudo-element we can style to achieve the full effect.&lt;/p&gt;
&lt;p&gt;The first step is to establish the general portal shape:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .portal&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 44px/62px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0 15px 4px white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 72px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 48px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sets up the portal and uses the &lt;code&gt;border-radius&lt;/code&gt; property to create an oval shape, and a white box shadow creates a glow. A pseudo-element is then added that has similar dimensions, and the white border:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .portal:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 44px/62px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4px solid white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 72px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -4px
  &lt;span class=&quot;token property&quot;&gt;margin-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -4px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 48px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far these styles have both applied to portals in general. Since one is red and the other blue, we&#39;ll use separate sets of CSS rules to describe the characteristics specific to each. Firstly, the red portal:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .portal.red&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;#000000&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000000 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #ff4640 70%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 7px solid #ff4640&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;223px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 25px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 385px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .portal.blue&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;#000000&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000000 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #258aff 70%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 7px solid #258aff&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;586px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 25px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 4px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The red portal is given a background &lt;a href=&quot;http://docs.webplatform.org/wiki/css/functions/radial-gradient&quot;&gt;radial gradient&lt;/a&gt; and a red border. The transform in this case rotates it and places it on the left wall. The blue portal is similar but has a blue gradient applied and is positioned on the right wall. Both looked a little off in testing, so I added a 5 degree skew effect that seemed to make them look a little better.&lt;/p&gt;
&lt;h3 id=&quot;portal-glow&quot; tabindex=&quot;-1&quot;&gt;Portal glow&lt;/h3&gt;
&lt;p&gt;The HTML we added earlier included a &lt;code&gt;span&lt;/code&gt; tag within each of the two platforms. These spans were added so that they could be styled with a radial gradient to provide a glowing effect beneath each portal.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .platform-left span&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #f3cac8&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #c8b8ad 70px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #bcb3a8 90px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .platform-right span&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #cdebe8&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #c2cbc1 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #bcb3a8 60px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 60px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 280px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 150px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The two spans are positioned absolutely and given a red and blue gradient, positioned beneath each of the portals. A pseudo-element could have been used to achieve this effect, but since animating pseudo-elements is not well supported (even within versions of Webkit), a separate span is used in this case.&lt;/p&gt;
&lt;h3 id=&quot;the-door&quot; tabindex=&quot;-1&quot;&gt;The Door&lt;/h3&gt;
&lt;p&gt;One of the unexpected successes was the use of borders to create what looks like an opening in the right wall, representing the exit. To create this door I use a single div and some coloured borders that make it look like it&#39;s inset.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/door.png&quot; alt=&quot;Door&quot; /&gt;
&lt;p&gt;The door HTML is straightforward. Add the following within the &lt;em&gt;stage&lt;/em&gt; section.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;door&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Styling the door involves a few borders and then a transform that positions it in front of the right wall:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .door&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #efe8dd&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px solid #bcb3a8&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 7px solid #78552e&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 85px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;450px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 34px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 4px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 65px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Two borders are used to create the effect. The bottom and left borders match the platform and the side of the right wall, giving the impression of depth. Since there is no top border specified, the left border stops flush with the top of the div, which in this case works well.&lt;/p&gt;
&lt;h2 id=&quot;characters&quot; tabindex=&quot;-1&quot;&gt;Characters&lt;/h2&gt;
&lt;p&gt;With the portals and door in place, we need a person to jump through one and arrive on the other side. The first step is to create the person that jumps through the two portals.&lt;/p&gt;
&lt;p&gt;In my initial testing, I tried using one character and having the animation stop at the first portal, and immediately continue from the other side. However when I animated the single character there was a flicker as it moved between portals. To avoid this, I instead used two characters and animated them separately.&lt;/p&gt;
&lt;h3 id=&quot;building-the-character&quot; tabindex=&quot;-1&quot;&gt;Building the character&lt;/h3&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/dude1.png&quot; alt=&quot;The first of two characters to animate through the scene&quot; /&gt;
&lt;p&gt;The beginning character shape is made up of 2 main parts, a head and body. Legs are added using pseudo-elements on the body. A similar structure is also included to be used as a shadow:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dude one&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dude-shadow one&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since the shadow is contained within the character&#39;s containing div, it can be animated at the same time. The CSS is as follows:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.dude, .dude-shadow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dude figure, .dude-shadow figure&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dude figure.head, .dude-shadow figure.head&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 22px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dude figure.body, .dude-shadow figure.body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30px 30px 0 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 21px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 26px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dude figure.body:before, .dude figure.body:after, .dude-shadow figure.body:before, .dude-shadow figure.body:after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dude figure.body:before, .dude-shadow figure.body:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.dude figure.body:after, .dude-shadow figure.body:after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 14px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These rules double up in each case, describing both the character and their shadow. Each of the parts is absolutely positioned and &lt;code&gt;border-radius&lt;/code&gt; is used to create the round shapes. The leg pseudo-elements are described at once then each positioned in separate rules.&lt;/p&gt;
&lt;h3 id=&quot;character-1&quot; tabindex=&quot;-1&quot;&gt;Character 1&lt;/h3&gt;
&lt;p&gt;With the character shape specified, position the character at the starting position:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .dude.one&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;514px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 375px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;78deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .dude-shadow.one&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-12px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;8px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The CSS transforms position both the character itself but also the shadow. The opacity of the shadow is set to 0.1 rather than set it a grey colour. This allows background details to be seen behind the shadow.&lt;/p&gt;
&lt;p&gt;The first character is now at the starting position, and rotated to a similar angle to that in the video. We will add animation later to have them jump through the portals.&lt;/p&gt;
&lt;h3 id=&quot;armed&quot; tabindex=&quot;-1&quot;&gt;Armed&lt;/h3&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/dude2.png&quot; alt=&quot;The second of two characters to animate through the scene&quot; /&gt;
&lt;p&gt;The second character has some more detail, arms. The idea being when the character jumps through the portal, they&#39;ll celebeate by raising their arms. Here&#39;s the HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dude two&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;arm left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;arm right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;dude-shadow two&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;head&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;arm left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;arm right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The second character will begin the animation invisible, and then jump through the portal about halfway through the animation (after the first character reaches their portal). To set this up, this second character is positioned at the portal.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage .dude.two&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;610px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .dude.two figure.arm&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 8px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .dude.two figure.arm.left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -13px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;40deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .dude.two figure.arm.right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-40deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.stage .dude-shadow.two&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;12px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-16px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-6px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;30deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A second animation will be applied to the arms, in which they will also be invisible to begin with but then appear later.&lt;/p&gt;
&lt;h2 id=&quot;the-stage-is-set&quot; tabindex=&quot;-1&quot;&gt;The stage is set&lt;/h2&gt;
&lt;p&gt;With the characters and the backdrop in place, the scene is ready for some animation.&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/portal/stage_set.png&quot; alt=&quot;The scene is ready, with 2 characters ready to be animated.&quot; /&gt;
&lt;p&gt;Let&#39;s look at how to make it look like the little person jumps through the first portal and arrives at the other.&lt;/p&gt;
&lt;h2 id=&quot;animation&quot; tabindex=&quot;-1&quot;&gt;Animation&lt;/h2&gt;
&lt;p&gt;If you &lt;a href=&quot;http://hop.ie/portal/&quot;&gt;view the demo&lt;/a&gt; you&#39;ll see a few animations taking place. Rather than go through all the animations that set up the scene, I&#39;ll focus on the animation of the character jumping through the portals.&lt;/p&gt;
&lt;h3 id=&quot;keyframe-animation&quot; tabindex=&quot;-1&quot;&gt;Keyframe animation&lt;/h3&gt;
&lt;p&gt;Timing and animating the HTML elements is achieved by using &lt;a href=&quot;http://docs.webplatform.org/wiki/css/atrules/@keyframes&quot;&gt;keyframes&lt;/a&gt;, and then attaching the set of keyframes to an element using the &lt;a href=&quot;http://docs.webplatform.org/wiki/css/properties/animation&quot;&gt;animation&lt;/a&gt; property.&lt;/p&gt;
&lt;p&gt;The first thing is to animate the first character, to have them approach and then jump into the left portal. Here&#39;s a set of keyframes that achieves this:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; move-dude-one&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Character flies into scene */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;514px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -10px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 375px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;78deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Waits a moment */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;1%, 18%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;514px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 375px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;78deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Moves toward the portal */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;34%, 39%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;284px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 375px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;78deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Pauses, them jumps in */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;41%, 42%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;234px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 375px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;78deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Vanishes */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;43%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;234px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 375px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;78deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;/* Note: Use prefixes, such as @-webkit-keyframes, @-moz-keyframes, etc! */&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Keyframes are a series of steps, described using percentages. The percentage relates to the animation time, so that if an animation was to last 10 seconds, 10% would be the 1 second mark. 90% would be the 9 second mark.&lt;/p&gt;
&lt;p&gt;To have the characters jumping through the portals in a nice loop, we&#39;ll set two animations that are each 10 seconds long so that they match. I have put some inline comments that describe each stage of the animation. The &lt;code&gt;transform&lt;/code&gt; property is used at each stage to set the characters position and angle.&lt;/p&gt;
&lt;p&gt;At 43% through the animation, the character&#39;s &lt;code&gt;opacity&lt;/code&gt; is set to 0. This is when the first character vanishes into the portal. The second character should therefore appear at 43% through it&#39;s animation.&lt;/p&gt;
&lt;p&gt;Before we do that, let&#39;s apply this first animation to the first character:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.dude.one&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; move-dude-one 10s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;animation&lt;/code&gt; property above applies the animation to the &lt;em&gt;dude one&lt;/em&gt; element. It attaches it with the animation name, sets it to last for 10 seconds, and suggests that it loop infinitely.&lt;/p&gt;
&lt;p&gt;An opacity of 0 is set to ensure the character is invisible before the animation starts.&lt;/p&gt;
&lt;p&gt;Having done that let&#39;s set up the corresponding animation keyframes for the second character:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; move-dude-two&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Dude be invisible */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 42%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;610px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Apparato! */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;42.5%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;610px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Move onto the platform */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;46%, 75%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;610px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 40px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Stand there for a bit */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;76%, 97%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;610px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -10px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Fly up into the sky! */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;98%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate3D&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;610px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -10px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; arms&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* No arms */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 53%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Yes arms! */&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;54%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As planned, this animation begins around the 42% mark. The character leaps out of the portal, stands around for a bit, then is whisked away into the sky. A second set of keyframes describe the arms animation. These start off invisible and then show around halfway through the animation.&lt;/p&gt;
&lt;p&gt;We can apply these keyframes to the second dude&#39;s element as follows:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.dude.two&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; move-dude-two 10s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.dude.two figure.arm&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; arms 10s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this way the two animations are being applied. Since both are set to last 10 seconds, and loop infinitely, they should match up nicely with the timing of the first animation.&lt;/p&gt;
&lt;p&gt;If you haven&#39;t already, &lt;a href=&quot;http://hop.ie/portal/&quot;&gt;check out the finished result&lt;/a&gt; in a modern browser, though preferably not Internet Explorer.&lt;/p&gt;
&lt;h2 id=&quot;caveats-%26-browser-quirks&quot; tabindex=&quot;-1&quot;&gt;Caveats &amp;amp; browser quirks&lt;/h2&gt;
&lt;p&gt;While we&#39;re on the subject of browsers, I should note that this is not going to work currently in Internet Explorer. Firefox is a bit &lt;em&gt;meh&lt;/em&gt; but not bad, Safari&#39;s almost there (waiting for Apple to patch webkit at long last), and Chrome is 100%. Hey, browsers gonna browse.&lt;/p&gt;
&lt;p&gt;Performance is pretty good across various devices (browser issues aside). Testing on an iPhone with Safari and it performs better than Chrome on a laptop. This is because the CSS rules used (3D transforms) make use of the graphic hardware.&lt;/p&gt;
&lt;h2 id=&quot;demo-and-contact-info&quot; tabindex=&quot;-1&quot;&gt;Demo and contact info&lt;/h2&gt;
&lt;p&gt;Check out the &lt;a href=&quot;http://hop.ie/portal&quot;&gt;online Portal CSS demo&lt;/a&gt; or download the &lt;a href=&quot;https://github.com/donovanh/portal&quot;&gt;source from Github&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Spheres</title>
    <link href="https://cssanimation.rocks/spheres/"/>
    <updated>2015-08-22T00:00:00Z</updated>
    <id>https://cssanimation.rocks/spheres/</id>
    <content type="html">&lt;p&gt;Using the CSS &lt;code&gt;border-radius&lt;/code&gt; property, we can create rounded shapes and circles. Add some gradients and they become spheres. Let&#39;s try that, and add some animation to bring them to life.&lt;/p&gt;
&lt;h2 id=&quot;flat-design&quot; tabindex=&quot;-1&quot;&gt;Flat design&lt;/h2&gt;
&lt;p&gt;There are two ways we could approach making spheres with CSS.&lt;/p&gt;
&lt;p&gt;One is to create an actual 3D sphere using lots of elements. There are some &lt;a href=&quot;http://codepen.io/peterwestendorp/pen/wGECk&quot;&gt;beautiful&lt;/a&gt; &lt;a href=&quot;http://www.cssplay.co.uk/menu/cssplay-3D-sphere.html&quot;&gt;examples&lt;/a&gt; of these. A potential downside though is that these require the browser display many elements, which can impact performance. They also tend to look a bit rough as a smooth sphere would require many elements.&lt;/p&gt;
&lt;p&gt;Instead of this I&#39;ll try a second approach, making use of CSS gradients to add shading and create the 3D effect on a single element.&lt;/p&gt;
&lt;h2 id=&quot;demo-and-source-code&quot; tabindex=&quot;-1&quot;&gt;Demo and source code&lt;/h2&gt;
&lt;p&gt;All the examples mentioned can be found via &lt;a href=&quot;http://codepen.io/donovanh&quot;&gt;my Codepen account&lt;/a&gt;, or by selecting the &amp;quot;Edit on Codepen&amp;quot; links in each example below.&lt;/p&gt;
&lt;p&gt;In the code examples, I&#39;ve left out any browser prefixes. I&#39;d recommend using a tool like &lt;a href=&quot;http://css-tricks.com/autoprefixer/&quot;&gt;Autoprefixer&lt;/a&gt;, or add in prefixes as needed.&lt;/p&gt;
&lt;h2 id=&quot;basic-shape&quot; tabindex=&quot;-1&quot;&gt;Basic shape&lt;/h2&gt;
&lt;p&gt;Before adding details, we&#39;ll create the initial circle shape. Begin with the HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;circle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;re using an &lt;code&gt;figure&lt;/code&gt; element here, but it could be any element. Figure is an element used in HTML5 to represent an image or diagram that is a part of the content that could be removed without affecting the content&#39;s meaning.&lt;/p&gt;
&lt;p&gt;To create a circle from this &lt;code&gt;figure&lt;/code&gt; element, I&#39;ll give it a width and height, and a border radius of 50%. Anything over 50% will result in a fully rounded corner.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.circle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A circle appears.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;sdLhc&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;p&gt;Now that we have a basic circle, we can start to style it up into something more spherical.&lt;/p&gt;
&lt;h2 id=&quot;shading-101&quot; tabindex=&quot;-1&quot;&gt;Shading 101&lt;/h2&gt;
&lt;p&gt;The first thing most 3D-sphere tutorials do is add a single radial gradient, slight up and to the left of the center of a circle.&lt;/p&gt;
&lt;p&gt;We can do this using the following CSS:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.circle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 100px 100px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #5cabff&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should get something like this:&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;zDqAs&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h3 id=&quot;radial-gradients&quot; tabindex=&quot;-1&quot;&gt;Radial gradients&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;radial-gradient&lt;/code&gt; property takes a few arguments. The first is the center position for the start of the gradient. This follows the form &lt;code&gt;*shape* at *position*&lt;/code&gt;. In this case case, it&#39;s a circle with it&#39;s center position 100 pixels in from the left and 100 pixels from the top.&lt;/p&gt;
&lt;p&gt;Next a series of colours is specified. You can specify more than two colours, but it is then necessary to include a distance with each one so that the gradient knows when to blend each colour into the next.&lt;/p&gt;
&lt;p&gt;In this example just two colours are specified. This lets the browser assumes the first is 0% and the latter is 100%, and it draws the gradient between these to colours. If we wanted other steps in the gradient, we could specify distances in pixels or percentages, as you&#39;ll see later.&lt;/p&gt;
&lt;p&gt;So we have something that looks a bit 3D-ish. It&#39;s &lt;em&gt;ok&lt;/em&gt;, but let&#39;s try to make it look a bit nicer.&lt;/p&gt;
&lt;h2 id=&quot;shadows-%26-3d&quot; tabindex=&quot;-1&quot;&gt;Shadows &amp;amp; 3D&lt;/h2&gt;
&lt;p&gt;Depending on what sort shading you apply to the surface, you can create different looking spheres. First though let&#39;s set up a scene to place the ball in.&lt;/p&gt;
&lt;p&gt;The HTML we&#39;ll use for this has a couple more elements:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ball&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shadow&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &amp;quot;ball&amp;quot; element has been given a span which we&#39;ll use to create a shadow, and it has been wrapped in a &lt;code&gt;stage&lt;/code&gt; div. The stage div is useful when we want to set some perspective and position the shadow, making it look more 3D.&lt;/p&gt;
&lt;p&gt;Apply some styles to the stage and position a shadow to set the scene.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 300px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; inline-block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50% 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.ball .shadow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.4&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 40%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-150px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that I&#39;m not showing prefixes in this examples CSS. The Codepen examples contain fully prefixed CSS. In the above I set up the &lt;code&gt;stage&lt;/code&gt; div to have &lt;code&gt;perspective&lt;/code&gt; of 1,200 pixels. The perspective property is like the vanishing point in a 3D scene.&lt;/p&gt;
&lt;p&gt;The ball&#39;s shadow is then placed by giving it a radial gradient, but then positioning it using a &lt;code&gt;transform&lt;/code&gt;. Transforms in CSS let you rotate, scale, move or skew things in a 3D space. The shadow is rotated 90 degrees on the X axis, and then is pulled down 150 pixels to the base of the ball.&lt;/p&gt;
&lt;p&gt;Since we established a perspective value on the stage container, we end up looking down on it and can see it as a stretched oval shape.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;pwGxn&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;p&gt;It&#39;s starting to look a bit better now. Let&#39;s add more shading to the ball itself.&lt;/p&gt;
&lt;h2 id=&quot;multiple-shaders&quot; tabindex=&quot;-1&quot;&gt;Multiple shaders&lt;/h2&gt;
&lt;p&gt;Very rarely in the real world would you find objects lit from just one angle. Surfaces reflect light onto other surfaces and the end results in various light sources mixed together. To create a more realistic looking ball, we&#39;ll make it look light there are two light sources by using a pseudo-element to add two gradients.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.ball&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; inline-block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 120%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #81e8f6&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #76deef 10%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #055194 80%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #062745 100%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.ball:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 90%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 90%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 0px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #ffffff&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 58%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;blur&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have two slightly more complex gradients.&lt;/p&gt;
&lt;p&gt;The first gradient is a subtle under-lighting effect and it applied to the &lt;code&gt;ball&lt;/code&gt; element. The center of the gradient is positioned half-way across and at 120% of the ball&#39;s height. This places the center off the ball&#39;s surface. I did this so that the sharp ending colour wasn&#39;t visible, resulting in a smoother gradient.&lt;/p&gt;
&lt;p&gt;The second gradient is a highlight, placed at the top. It&#39;s set to be 90% of the ball&#39;s width and 90% of its height. The gradient is centered at the top so that it fades out at around halfway down the ball.&lt;/p&gt;
&lt;p&gt;I&#39;ve used the &lt;code&gt;before&lt;/code&gt; pseudo-element rather than create a new element to contain the shading.&lt;/p&gt;
&lt;p&gt;Since this highlight gradient has a sharp edge, I&#39;ve made use of the &lt;code&gt;blur&lt;/code&gt; effect to soften the highlight. Unfortunately this is currently only a webkit feature (Chrome and Safari) but it may be more useful in future across other browsers.&lt;/p&gt;
&lt;p&gt;Both gradients combine to create a much nicer effect:&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;fEaru&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h2 id=&quot;shinier&quot; tabindex=&quot;-1&quot;&gt;Shinier&lt;/h2&gt;
&lt;p&gt;The effect so far is quite soft, so let&#39;s add some shine and create something more like a snooker ball.&lt;/p&gt;
&lt;p&gt;To achieve this we&#39;ll make use of a soft under light as before, but adjust the top highlight to be smaller and sharper. We&#39;ll need to make use of two psuedo-selectors to contain the ball&#39;s colour, a bottom highlight and a reflection.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.ball&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; inline-block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 120%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #323232&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #0a0a0a 80%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #000000 100%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.ball:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 120%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 70%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2.5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.6&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 90%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;blur&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.ball:after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 14%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 24%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-80px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-20deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;blur&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;10px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have the initial colour being applied as a subtle gradient on the ball itself. The &lt;code&gt;before&lt;/code&gt; pseudo-element contains a lighter highlight, which again starts at the bottom of the ball and creates the effect of reflected light from the surface.&lt;/p&gt;
&lt;p&gt;The new addition here is the &lt;code&gt;after&lt;/code&gt; psuedo-selector. It contains a circular gradient that starts almost opaque white at the center, and fades to transparent at around the 24% mark. This creates a white shiny effect, but to make it look like it&#39;s reflecting off a three dimensional object, we apply a CSS &lt;code&gt;transform&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The transform moves the shine effect left 80 pixels then up 90 pixels, and to adds a skew effect. The skew effect stretches the circle along the X-axis, so that it looks more like the sheen you&#39;d find on a shiny ball.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;LuEAB&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h3 id=&quot;8-ball&quot; tabindex=&quot;-1&quot;&gt;8-ball&lt;/h3&gt;
&lt;p&gt;While we&#39;re making a pool ball, let&#39;s go the extra step and add the number 8.&lt;/p&gt;
&lt;p&gt;We&#39;ll need an extra element to contain the 8, as well as some styles to place it on the ball.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ball&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shadow&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;eight&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.ball .eight&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 110px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 110px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;68px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-60px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;2deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.ball .eight:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;8&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 80px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin-left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -40px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 44px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -40px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Arial&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 90px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;line-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 104px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The 100% border radius is again used to create a circle, and this circle is positioned at the top right using the &lt;code&gt;transform&lt;/code&gt; property. Rather that put the number 8 into the content, I&#39;m using the &lt;code&gt;before&lt;/code&gt; psuedo-selector to add the content via CSS, and then skewing the number in a similar way to the containing circle.&lt;/p&gt;
&lt;p&gt;The result is a shiny 8-ball.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;nzmJq&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h2 id=&quot;got-my-eye-on-you&quot; tabindex=&quot;-1&quot;&gt;Got my eye on you&lt;/h2&gt;
&lt;p&gt;One of the great things about CSS transforms is that they can be animated. Using CSS &lt;code&gt;keyframes&lt;/code&gt; for animation, you can describe a series of transforms as an animation and apply that to an element. To show this, I&#39;ll create and animate an eyeball.&lt;/p&gt;
&lt;p&gt;First step is to adjust some of the colours use in the 8-ball example. A few tweaks and it&#39;s looking a lot more like an eye. First, the HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;ball&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;shadow&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;iris&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The bulk of the CSS is similar to the 8-ball, with the exception of the iris and pupil parts.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.iris&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 40%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 40%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;radial-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;circle at 50% 50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #208ab4 0%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #6fbfff 30%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; #4381b2 100%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;68px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-60px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;2deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; move-eye-skew 5s ease-out infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.iris:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 37.5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 37.5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 31.25%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 31.25%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.iris:after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 31.25%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 31.25%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 18.75%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 18.75%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 255&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A blue gradient forms the coloured part of the iris, and then the pupil and a highlight are created as pseudo-elements. I&#39;ve also added the animation property to the iris element. Animations are attached to elements using a format like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;animation: animation-name 5s ease-out infinite;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this case we&#39;d be applying an animation called &amp;quot;animation-name&amp;quot;, setting it to last 5 seconds, loop indefinitely, and applying an easing value of &amp;quot;ease-out&amp;quot;. Ease-out is when the animation slows down as it reaches the end, creating a more natural effect.&lt;/p&gt;
&lt;p&gt;Without the animation yet created, we have a very static eyeball.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;nwsqa&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;p&gt;Lets create some keyframes to describe how the eyeball should move.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; move-eye-skew&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;20%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-68px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;30px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;15deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-10deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.95&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;25%, 44%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;50%, 60%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;68px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-40px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;skewY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;2deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.95&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;66%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Animation keyframes in CSS can seem tricky at first. What you&#39;re doing is describing the state of the element at a series of stages. Each state is mapped to a percentage. In this case the iris will begin with no transforms applied. Then at 20%, a transform will apply in which it is moved and skewed to the left. The gap between 0 and 20% is automatically calculated by the browser, creating a smooth transition between these two points.&lt;/p&gt;
&lt;p&gt;This continues across each of the keyframes, and the entire animation in this case takes 5 seconds, as specified earlier.&lt;/p&gt;
&lt;p&gt;Don&#39;t forget to create moz, ms, o and non-prefixed versions of keyframe animations as some browsers need the prefixes.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;iBolr&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h2 id=&quot;bubbles&quot; tabindex=&quot;-1&quot;&gt;Bubbles&lt;/h2&gt;
&lt;p&gt;Using a combination of shading and animation can produce all sorts of interesting and varied effects. How about some bubbles?&lt;/p&gt;
&lt;p&gt;Creating the bubble look is similar to before, using more transparency in the main colour and two pseudo-elements to add shine.&lt;/p&gt;
&lt;p&gt;The animation makes use of the &lt;code&gt;scale&lt;/code&gt; transform to make the entire bubble wobble.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; bubble-anim&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;20%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.95&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1.05&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;48%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1.1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.9&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;68%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.98&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1.02&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;80%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1.02&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scaleX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.98&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;97%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The animation applies to the entire bubble and its pseudo-elements.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;pvrzK&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h2 id=&quot;using-images&quot; tabindex=&quot;-1&quot;&gt;Using images&lt;/h2&gt;
&lt;p&gt;So far all the balls have been created without using any images. Applying a background image can add more detail, and still take advantage of the CSS shading within the pseudo-elements. For example, an unshaded texture of a tennis ball:&lt;/p&gt;
&lt;img src=&quot;http://hop.ie/balls/images/tennisball.png&quot; style=&quot;max-width:200px&quot; alt=&quot;Unshaded tennis ball image&quot; /&gt;
&lt;p&gt;Adding some CSS gradients can create the illusion of depth.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;result&quot; data-href=&quot;vsEIK&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h3 id=&quot;around-the-world&quot; tabindex=&quot;-1&quot;&gt;Around the world&lt;/h3&gt;
&lt;p&gt;Animation can also be applied to the position of background images. Using this we can create a spinning globe.&lt;/p&gt;
&lt;p&gt;This flat image was stretched a little at the top and bottom to be used as a background image.&lt;/p&gt;
&lt;img src=&quot;http://hop.ie/balls/images/world-map-one-color.png&quot; alt=&quot;Flat world map&quot; /&gt;
&lt;p&gt;With some shading and animation added, a 3D-style globe can be created. Select &amp;quot;Result&amp;quot; in this Codepen to see it in action. I&#39;ve set it to display the HTML by default as the performance on this example was pretty slow, causing the fan to kick in on my development laptop.&lt;/p&gt;
&lt;p&gt;Note: Many thanks to Sidoruk Sergey ‏(&lt;a href=&quot;http://twitter.com/Sidoruk_SV&quot;&gt;@Sidoruk_SV&lt;/a&gt;) for upgrading this globe. It&#39;s looking great.&lt;/p&gt;
&lt;div class=&quot;codepen&quot; data-height=&quot;400&quot; data-type=&quot;html&quot; data-href=&quot;GBIiv&quot; data-user=&quot;donovanh&quot; data-safe=&quot;true&quot;&gt; &lt;/div&gt;
&lt;h2 id=&quot;resources&quot; tabindex=&quot;-1&quot;&gt;Resources&lt;/h2&gt;
&lt;p&gt;Some &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/radial-gradient&quot;&gt;good info about radial gradients&lt;/a&gt; in case you&#39;d like to know more.&lt;/p&gt;
&lt;p&gt;Looking for more 3D examples? Check out &lt;a href=&quot;https://cssanimation.rocks/portal/&quot;&gt;Portal CSS&lt;/a&gt; for inspiration.&lt;/p&gt;
&lt;h2 id=&quot;feedback&quot; tabindex=&quot;-1&quot;&gt;Feedback&lt;/h2&gt;
&lt;p&gt;All the examples mentioned can be found via &lt;a href=&quot;http://codepen.io/donovanh&quot;&gt;my Codepen account&lt;/a&gt;. Many thanks to Chris and the team for making such a fantastic resource.&lt;/p&gt;
&lt;p&gt;If you have any questions about the above, get in touch &lt;a href=&quot;mailto:hello@cssanimation.rocks&quot;&gt;by email&lt;/a&gt; or &lt;a href=&quot;http://twitter.com/cssanimation&quot;&gt;on Twitter&lt;/a&gt;.&lt;/p&gt;
&lt;script src=&quot;https://codepen.io/assets/embed/ei.js&quot;&gt; &lt;/script&gt;
</content>
  </entry><entry>
    <title>Zelda: A link to the CSS</title>
    <link href="https://cssanimation.rocks/zelda/"/>
    <updated>2015-11-17T00:00:00Z</updated>
    <id>https://cssanimation.rocks/zelda/</id>
    <content type="html">&lt;p&gt;The Zelda games have always been close to my heart. In this post, we&#39;ll try to recreate the iconic introduction to what might be the best game ever, A Link to the Past.&lt;/p&gt;
&lt;h2 id=&quot;zelda%3A-linked-to-the-past&quot; tabindex=&quot;-1&quot;&gt;Zelda: Linked to the Past&lt;/h2&gt;
&lt;p&gt;The idea is to create something that would look like this:&lt;/p&gt;
&lt;p data-height=&quot;487&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;phnsJ&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; class=&quot;codepen&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;getting-started%3A-html&quot; tabindex=&quot;-1&quot;&gt;Getting started: HTML&lt;/h2&gt;
&lt;p&gt;To get started, I created the HTML structure to which I&#39;d be applying the styles. The layout requires three 3D triangles, and some text to sit on top. I began with a single triangle:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;triangle&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;side1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;side2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;side3&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The front and back pieces needed to be triangular, with 3 rectangles covering the left, right and bottom sides. HTML isn&#39;t great at producing shapes other than rectangles, but we can create a triangle shape using borders.&lt;/p&gt;
&lt;p data-height=&quot;298&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;pjYOzm&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; class=&quot;codepen&quot;&gt;
&lt;/p&gt;&lt;p&gt;[TODO: Explain the CSS behind creating a triangle]&lt;/p&gt;
&lt;h2 id=&quot;setting-the-stage&quot; tabindex=&quot;-1&quot;&gt;Setting the stage&lt;/h2&gt;
&lt;p&gt;Once we have the shape in place, we&#39;ll need to place a back piece and position them both in 3D space. A containing &amp;quot;stage&amp;quot; div is needed to achieve this. We can apply a perspective value to the stage and any objects on it will be then drawn in relation to each other.&lt;/p&gt;
&lt;div class=&quot;example-with-code clearfix&quot;&gt;
  &lt;div class=&quot;left&quot;&gt;
```html
&lt;div class=&quot;stage example example2&quot;&gt;
  &lt;div class=&quot;triangle&quot;&gt;
    &lt;figure class=&quot;front&quot;&gt; &lt;/figure&gt;
    &lt;figure class=&quot;back&quot;&gt; &lt;/figure&gt;
  &lt;/div&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;div class=&quot;right&quot;&gt;
&lt;pre&gt;&lt;code&gt;.stage
  @include perspective(800px)
  @include perspective-origin(120% -200px)

figure.front
  +arrow(150px, 150px, up, #ffe403)
  @include transform(translateZ(80px))

figure.back
  +arrow(150px, 150px, up, #ffd200)
  @include transform(translateZ(-80px))
&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The 3D positioning is achieved by using the &lt;a href=&quot;http://docs.webplatform.org/wiki/css/properties/transform&quot;&gt;translateZ transform&lt;/a&gt;. The front face is brought forward 80 pixels and the back face pushed back 80px.&lt;/p&gt;
&lt;p&gt;I also rotated the back panel 180 degrees on the Y axis so that it now faces out toward the back.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;perspective&lt;/em&gt; value relates to the depth of the scene, and larger values produce more extreme distortion. Similar to this, the &lt;em&gt;perspective-origin&lt;/em&gt; value is used to move the viewpoint. In this case, the viewpoint is looking down from 200 pixels up, and from off to the right side of the stage.&lt;/p&gt;
&lt;h2 id=&quot;sides&quot; tabindex=&quot;-1&quot;&gt;Sides&lt;/h2&gt;
&lt;p&gt;With the front and back in place, there are gaps to fill on the sides. To fill these, rectangular divs can be positioned like so:&lt;/p&gt;
&lt;div class=&quot;example-with-code clearfix&quot;&gt;
  &lt;div class=&quot;left&quot;&gt;
```html
&lt;div class=&quot;stage example example3&quot;&gt;
  &lt;div class=&quot;triangle&quot;&gt;
    &lt;figure class=&quot;front&quot;&gt; &lt;/figure&gt;
    &lt;figure class=&quot;back&quot;&gt; &lt;/figure&gt;
    &lt;figure class=&quot;side1&quot;&gt; &lt;/figure&gt;
    &lt;figure class=&quot;side2&quot;&gt; &lt;/figure&gt;
    &lt;figure class=&quot;side3&quot;&gt; &lt;/figure&gt;
  &lt;/div&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;div class=&quot;right&quot;&gt;
&lt;pre&gt;&lt;code&gt;figure
  &amp;amp;.side1
```
content: &quot; &quot;
display: block
position: absolute
height: 168px
width: 40px
background-color: #ffd200
@include transform(translateY(-9px) translateX(18px) rotateY(-90deg) rotateX(26.5deg))
```
&lt;p&gt;&amp;amp;.side2&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;content: &amp;quot; &amp;quot;
display: block
position: absolute
height: 168px
width: 40px
background-color: #ffd200
@include transform(translateY(-9px) translateX(92px) rotateY(90deg) rotateX(26.5deg))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;amp;.side3&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;content: &amp;quot; &amp;quot;
background-color: #ffd200
width: 150px
height: 40px
@include transform(translateY(130px) rotateX(-90deg))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;One small adjustment made in this example was to rotate the back panel 180 degrees to ensure it was facing outwards. With the back-faces hidden, it would have been invisible otherwise.&lt;/p&gt;
&lt;h2 id=&quot;three-triangles&quot; tabindex=&quot;-1&quot;&gt;Three triangles&lt;/h2&gt;
&lt;p&gt;With one triangle done, it was straightforward to position three of them on the stage. I copied the div called &amp;quot;triangle&amp;quot; above, and replicated it three times. I then added a class &amp;quot;one&amp;quot;, &amp;quot;two&amp;quot; and &amp;quot;three&amp;quot; to each so they could be referenced individually:&lt;/p&gt;
&lt;div class=&quot;example-with-code clearfix&quot;&gt;
  &lt;div class=&quot;left&quot;&gt;
```html
&lt;div class=&quot;stage example example4&quot;&gt;
  &lt;div class=&quot;scaler&quot;&gt;
    &lt;div class=&quot;triangle one&quot;&gt;
      &lt;figure class=&quot;front&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;back&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side1&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side2&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side3&quot;&gt; &lt;/figure&gt;
    &lt;/div&gt;
    &lt;div class=&quot;triangle two&quot;&gt;
      &lt;figure class=&quot;front&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;back&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side1&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side2&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side3&quot;&gt; &lt;/figure&gt;
    &lt;/div&gt;
    &lt;div class=&quot;triangle three&quot;&gt;
      &lt;figure class=&quot;front&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;back&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side1&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side2&quot;&gt; &lt;/figure&gt;
      &lt;figure class=&quot;side3&quot;&gt; &lt;/figure&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;div class=&quot;right&quot;&gt;
&lt;pre&gt;&lt;code&gt;.triangle
  @include animation(rotate 5s infinite linear)
&lt;p&gt;&amp;amp;.two&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;top: 150px
left: 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;amp;.three&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;top: 150px
left: 150px
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&quot;styling-the-text&quot; tabindex=&quot;-1&quot;&gt;Styling the text&lt;/h2&gt;
&lt;p&gt;To create the proper Zelda atmosphere, the right fonts were needed. For the main font, &lt;a href=&quot;http://www.google.com/fonts/specimen/EB+Garamond&quot;&gt;EB Garamond&lt;/a&gt; seemed a decent choice. The smaller text looks good with &lt;a href=&quot;http://www.google.com/fonts/specimen/Old+Standard+TT&quot;&gt;Old Standard TT&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Including these fonts involves referencing them in the head of your HTML:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;http://fonts.googleapis.com/css?family=EB+Garamond&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;stylesheet&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;text/css&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;http://fonts.googleapis.com/css?family=Old+Standard+TT&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;stylesheet&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;text/css&lt;span class=&quot;token punctuation&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can then use them in your CSS:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;h1
  font-family: &amp;quot;EB Garamond&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The finishing touch was to add a border around the text:&lt;/p&gt;
&lt;div class=&quot;example-with-code clearfix&quot;&gt;
  &lt;div class=&quot;left&quot;&gt;
```html
&lt;div class=&quot;stage&quot;&gt;
  &lt;link href=&quot;http://fonts.googleapis.com/css?family=Old+Standard+TT&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
  &lt;h1 class=&quot;zelda-style&quot;&gt;ZELDA&lt;/h1&gt;
&lt;/div&gt;
```
  &lt;/div&gt;
  &lt;div class=&quot;right&quot;&gt;
&lt;pre&gt;&lt;code&gt;.zelda-style
  font-family: &quot;EB Garamond&quot;
  @include text-fill-color(#b62f22)
  @include text-stroke-color(#8b3536)
  @include text-stroke-width(2px)
  margin: 10px auto
&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&quot;bringing-it-together&quot; tabindex=&quot;-1&quot;&gt;Bringing it together&lt;/h2&gt;
&lt;p&gt;To achieve the animation I put together a few different animations and timed them so that they all worked together. Using keyframe animation in CSS is made much easier by using SASS, and I used a few basic mixins to make the process easier. I’m using Sass with the &lt;a href=&quot;http://compass-style.org/&quot;&gt;Compass&lt;/a&gt; framework, but to add support for animation and keyframes to Compass, you’ll need &lt;a href=&quot;https://gist.github.com/donovanh/5426633&quot;&gt;this gist&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;animation-1%3A-rotating&quot; tabindex=&quot;-1&quot;&gt;Animation 1: Rotating&lt;/h3&gt;
&lt;p&gt;The spinning effect is creating using the following keyframes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@include keyframes(rotate)
  0%
    @include transform(rotateY(0))
  100%
    @include transform(rotateY(360deg))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To apply this animation to the figures, the following SASS is used. Note, it makes use of the &amp;quot;animation&amp;quot; mixin &lt;a href=&quot;https://gist.github.com/donovanh/5426633&quot;&gt;found here&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;figure
  @include animation(rotate 5s infinite linear)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This calls the &amp;quot;animation&amp;quot; mixin and passes in the name of the keyframes (rotate), the duration of 5 seconds, repeated forever. It also specifies that the animation easing be &amp;quot;linear&amp;quot;, which maintains a constant speed throughout the animation.&lt;/p&gt;
&lt;h3 id=&quot;animation-2%3A-tumbling-triangles&quot; tabindex=&quot;-1&quot;&gt;Animation 2: Tumbling triangles&lt;/h3&gt;
&lt;p&gt;The introduction of the figures sees them tumble into place. This is done by transitioning them from an initial position offset to the top, left or right, while applying 360 degrees of rotation. These combine in the following keyframes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@include keyframes(introduce-1)
  0%
    top: -200px
    opacity: 0
  45%
    top: -100px
    @include transform(rotateY(180deg) rotateX(-180deg))
    opacity: 1
  90%, 100%
    top: 0
    @include transform(rotateY(360deg) rotateX(-360deg))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By putting the ending position of the animation at both 90% and 100%, it ensures that the animation stays still for a moment at the end of it&#39;s tumbling.&lt;/p&gt;
&lt;p&gt;Applying both these to the figures at the same time looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@include animation(rotate 5s infinite linear, introduce-1 5s linear)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;animation-3%3A-text&quot; tabindex=&quot;-1&quot;&gt;Animation 3: Text&lt;/h3&gt;
&lt;p&gt;The text overlay is invisible at first, and I wanted it to wait until after the tumbling animation had finished before fading into place. To achieve this, the following keyframes apply to the text:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@include keyframes(showZeldaText)
  0%, 80%
    @include transform(scale(0.6) translateZ(-100px))
    opacity: 0
    -webkit-filter: blur(2px)
  90%
    -webkit-filter: blur(0)
  100%
    @include transform(scale(1) translateZ(0))
    opacity: 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For 90% of the time, the text is invisible. Then in the last 10% the text scales up from 60% scale to 100%, while the opacity changes from invisible to visible.&lt;/p&gt;
&lt;p&gt;Since the text animation starts at the same time as the tumbling, it needs a longer time to run so that it lines up properly. In this case, I set it to run for 6.5 seconds:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;@include &lt;span class=&quot;token function&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;showZeldaText 6.5s linear&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With these in place, the last animation is the flash of background colour when the tumbling stops.&lt;/p&gt;
&lt;h3 id=&quot;animation-4%3A-background-flash&quot; tabindex=&quot;-1&quot;&gt;Animation 4: Background flash&lt;/h3&gt;
&lt;p&gt;The background starts black, then when the tumbling finishes, briefly flashes white before the background image is shown. This colour sequence is also timed to coincide with the appearance of the text. The keyframes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@include keyframes(animate-background)
  0%
    background: #000
  83%
    background: #000
  84%
    background: #fff
  87%, 100%
    background: #000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A similar set of keyframes is used to show the background image after the screen flashes.&lt;/p&gt;
&lt;h2 id=&quot;see-it-in-action&quot; tabindex=&quot;-1&quot;&gt;See it in action&lt;/h2&gt;
&lt;p&gt;Here&#39;s a &lt;a href=&quot;http://hop.ie/zelda&quot;&gt;live demo&lt;/a&gt;. It works reasonably in recent versions of Chrome, Safari and Firefox.&lt;/p&gt;
&lt;h2 id=&quot;have-a-go&quot; tabindex=&quot;-1&quot;&gt;Have a go&lt;/h2&gt;
&lt;p&gt;The HTML and CSS is &lt;a href=&quot;https://github.com/donovanh/zelda&quot;&gt;available on Github&lt;/a&gt;. Please fork, share, and have a play with it. If you&#39;d like to add to or fix something, pull requests are a fast way to becoming one of my favourite people. Do it!&lt;/p&gt;
&lt;h2 id=&quot;issues&quot; tabindex=&quot;-1&quot;&gt;Issues&lt;/h2&gt;
&lt;p&gt;IE10 support is basic, so any browser support improvements would be a good thing. There&#39;s also a bit of a glitch where the tumbling animation on the elements doesn&#39;t always start. It seems to happen in all browsers. Any suggestions on fixing that would be appreciated.&lt;/p&gt;
&lt;p&gt;I hope you enjoyed this post. I am more than happy to respond to questions and suggestions on Twitter at &lt;a href=&quot;http://twitter.com/donovanh&quot;&gt;@donovanh&lt;/a&gt;.&lt;/p&gt;
&lt;script async=&quot;&quot; src=&quot;https://assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
</content>
  </entry><entry>
    <title>Stereoscopic CSS</title>
    <link href="https://cssanimation.rocks/stereoscopic/"/>
    <updated>2015-11-17T00:00:00Z</updated>
    <id>https://cssanimation.rocks/stereoscopic/</id>
    <content type="html">&lt;p&gt;For a while I&#39;ve been blogging about making all sorts of 3D-style effects using CSS. In this post I take it one step further and try to make the scenes look &lt;strong&gt;even more three dimensional&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;See the &lt;a href=&quot;https://cssanimation.rocks/demo/stereoscopic&quot;&gt;stereoscopic cube demo&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;stereoscopes&quot; tabindex=&quot;-1&quot;&gt;Stereoscopes&lt;/h2&gt;
&lt;p&gt;There are many techniques used to try to convey a 3D image from a screen. One of the oldest is the use of red and green (or blue) coloured film, which when watched through red/green glasses produces a 3D effect.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/stereoscopic/old-movie.jpg&quot; alt=&quot;Old-style 3D effect&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://twitter.com/simurai&quot;&gt;Simurai&lt;/a&gt; has put some work into this and created a nice &lt;a href=&quot;http://simurai.com/post/802968365/css3d-css3-3d-text&quot;&gt;CSS3D&lt;/a&gt; plugin to achieve it.&lt;/p&gt;
&lt;p&gt;The downside to this is that the film can only be monochrome, as the colours are limited to being used to create the 3D effect.&lt;/p&gt;
&lt;h3 id=&quot;side-by-side-stereoscopy&quot; tabindex=&quot;-1&quot;&gt;Side-by-side stereoscopy&lt;/h3&gt;
&lt;p&gt;A second approach to presenting 3D is to make use of an ability some of us have to cross our eyes. The idea is to present two scenes side by side, each presented from a slightly different angle. If the viewer can cross their eyes, the two images combine to create a 3D effect.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/stereoscopic/example.png&quot; alt=&quot;How two images combine to form a 3D version&quot; /&gt;&lt;/p&gt;
&lt;p&gt;While this may not work for everyone, it&#39;s great when it works and doesn&#39;t limit the number of colours a scene can include. Some &lt;a href=&quot;http://www.flickr.com/photos/ytf/5557882900/&quot;&gt;photographs show this effect&lt;/a&gt; nicely.&lt;/p&gt;
&lt;p&gt;To give it a go, try looking at the following image from about two feet away from your monitor. Gently cross your eyes until the two images merge together, and if you get them to line up just right, it should look like it&#39;s 3D.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/stereoscopic/stereoscopic-hop.ie.png&quot; alt=&quot;The finished stereoscopic 3D scene with just CSS&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This double-image technique is most notably used in the new &lt;a href=&quot;http://www.oculusvr.com/&quot;&gt;Oculus Rift headset&lt;/a&gt;. While I don&#39;t have one to test this against, I believe it&#39;s possible to display HTML pages within the headset, so some form of this technique might be useful there.&lt;/p&gt;
&lt;h2 id=&quot;warning&quot; tabindex=&quot;-1&quot;&gt;Warning&lt;/h2&gt;
&lt;p&gt;Just a heads up, but if you are going to spend a lot of time staring at the screen with your eyes crossed, you might experience headaches. I know I did. Totally worth it though!&lt;/p&gt;
&lt;h2 id=&quot;set-the-scene&quot; tabindex=&quot;-1&quot;&gt;Set the scene&lt;/h2&gt;
&lt;p&gt;To get started we&#39;ll create a simple 3D scene using some HTML.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;cube&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;S&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bottom&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;3D!&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;S&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;C&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We have a containing stage &lt;code&gt;div&lt;/code&gt; here that will act as a stage for the cube to sit on, and within it the cube figure itself. The cube is made up of 6 parts.&lt;/p&gt;
&lt;p&gt;The &amp;quot;stage&amp;quot; div is needed so that the browser can establish some important 3D-related settings, such as the depth of the scene and the angle we&#39;re looking into the scene at. These things we set with the CSS.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.stage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 480px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 500px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1600px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This CSS sets up the stage with some proportions and sets a &lt;code&gt;perspective&lt;/code&gt; value. Perspective describes the depth of the scene, with smaller values producting more extreme-looking results. In this case, 1600 pixels looks pretty good, but you can try different values in your own scene to see how it feels.&lt;/p&gt;
&lt;h2 id=&quot;building-the-cube&quot; tabindex=&quot;-1&quot;&gt;Building the cube&lt;/h2&gt;
&lt;p&gt;The cube itself is made up of six elements. Using the CSS3 &lt;code&gt;transform&lt;/code&gt; property, we can manipulate these spans in the 3D space and position them where we like. First though we need to tell the browser that our intention is to move things around in 3D. Some CSS achieves this.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.cube&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; preserve-3d&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100px 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 120px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 140px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The main parts to note here are the &lt;code&gt;transform-style&lt;/code&gt; and &lt;code&gt;transform-origin&lt;/code&gt; properties. These tell the browser that this and any child elements will be capable of transforming within the context of the &amp;quot;stage&amp;quot; &lt;code&gt;figure&lt;/code&gt;, as well as describing the point around which any rotation, scaling or skewing can happen.&lt;/p&gt;
&lt;p&gt;Next up we need to specify the dimensions of the cube faces, and then magic them into place using the &lt;code&gt;transform&lt;/code&gt; property.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.cube span&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;line-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.5&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.back&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #f00&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;180deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.top&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #ff7400&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.bottom&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #aaa&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 10px 100px &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.7&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #099&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #0c0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.front&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #ff0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To make things more readable, I&#39;ve removed the various &amp;quot;-webkit&amp;quot; and &amp;quot;-moz&amp;quot; prefixes from the &lt;code&gt;tranform&lt;/code&gt; properties here.&lt;/p&gt;
&lt;p&gt;This CSS describes the general rules for the spans, that they be 200 pixels wide for example, and have white text. The rules that follow rotate and position each of the various faces using rotate and translate. Each face is given a background colour also.&lt;/p&gt;
&lt;h2 id=&quot;making-it-stereoscopic&quot; tabindex=&quot;-1&quot;&gt;Making it stereoscopic&lt;/h2&gt;
&lt;p&gt;Now that we have a scene with a 3D object, we can double it up and make it stereoscopic. Start by doubling up the HTML into a &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;right&lt;/code&gt; div.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;cube&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;S&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bottom&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;3D!&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;S&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;C&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;stage&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;figure&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;cube&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;back&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;S&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;top&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bottom&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;left&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;3D!&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;right&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;S&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;front&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;C&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;figure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The intention here is to divide the screen up into two, and place one cube beside the other. We again use some of that magic we call CSS to achieve the goal.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 960px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.left, .right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.left&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; left&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.right&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; right&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Our example doesn&#39;t need to be full screen sized, so I&#39;ve chosen to set it within a container column. Each of the two &lt;code&gt;divs&lt;/code&gt; is set to 50% width and floated left and right respectively.&lt;/p&gt;
&lt;p&gt;We now have two identical 3D objects. This isn&#39;t going be enough, we&#39;ll need to adjust for the different angles each eye needs. To do this we will override each &lt;code&gt;stage&lt;/code&gt; perspective-origin property.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.left .stage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 63.5% -340px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.right .stage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 36.5% -340px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The left stage is given a perspective approximately two thirds along the X-axis, to mimic what your right eye would expect, and the right stage given a value of around one third. I&#39;ve tweaked these by hand so they may need to be adjusted a little to work with your project.&lt;/p&gt;
&lt;p&gt;The end result should be two almost identical 3D CSS scenes, with slightly different perspectives.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/stereoscopic/stereoscopic-hop.ie.png&quot; alt=&quot;The finished stereoscopic 3D scene with just CSS&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You can see the &lt;a href=&quot;https://cssanimation.rocks/demo/stereoscopic&quot;&gt;animated stereoscopic version here&lt;/a&gt;.&lt;/p&gt;
&lt;!--
## More examples

Note: Some of these larger scenes can be more difficult to see as they require you cross your eyes more. If you have trouble with any, try zooming your browser out to make the scene a little smaller.

### Portal Orientation Video

![Portal CSS with the stereoscopic treatment](/images/posts/stereoscopic/portal.png)

See the [animated version here](https://cssanimation.rocks/demo/stereoscopic/portal.html). You can also [read how the it was made](/portal).

### Zelda Intro Screen

![Zelda intro screen with the stereoscopic treatment](/images/posts/stereoscopic/zelda.png)

See the [animated version here](https://cssanimation.rocks/demo/stereoscopic/zelda.html). You can also [read how the it was made](/zelda).

--&gt;
</content>
  </entry><entry>
    <title>Star Wars</title>
    <link href="https://cssanimation.rocks/starwars/"/>
    <updated>2015-12-10T00:00:00Z</updated>
    <id>https://cssanimation.rocks/starwars/</id>
    <content type="html">&lt;p&gt;Get out the popcorn! Today we&#39;re building the Star Wars movie title from the &amp;quot;The Force Awakens&amp;quot; trailer.&lt;/p&gt;
&lt;p data-height=&quot;468&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;pJzwEw&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; class=&quot;codepen&quot;&gt;&lt;/p&gt;
&lt;div class=&quot;callout&quot;&gt;
  &lt;p&gt;This is an excerpt from the course, &lt;a href=&quot;https://cssanimation.rocks/courses/animation-101/&quot;&gt;CSS Animation 101&lt;/a&gt;. For a limited time you can &lt;em&gt;pay what you want&lt;/em&gt;. &lt;a href=&quot;https://cssanimation.rocks/courses/animation-101/&quot;&gt;Check it out!&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This example combines CSS animation with some other CSS properties you may find helpful, specifically the transforms &lt;code&gt;scale&lt;/code&gt;, &lt;code&gt;translate&lt;/code&gt; and &lt;code&gt;rotate&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;transforms&quot; tabindex=&quot;-1&quot;&gt;Transforms&lt;/h2&gt;
&lt;p&gt;While it may sound like it creates an animation, the transform property is in fact used setting a static position, skew or scale of an element. We can use it to create great effects but to do so we need to have a different transform for each keyframe or state we animate.&lt;/p&gt;
&lt;h2 id=&quot;transform%3A-scale()%2C-translatez()-and-rotatey()&quot; tabindex=&quot;-1&quot;&gt;Transform: scale(), translateZ() and rotateY()&lt;/h2&gt;
&lt;p&gt;We can make elements larger or smaller using &lt;code&gt;scale&lt;/code&gt;. Using &lt;code&gt;translateZ&lt;/code&gt; we can move elements in the Z-axis. This axis would be the one represented by drawing a line from you, through the monitor.&lt;/p&gt;
&lt;p&gt;In this case we&#39;ll be using a combination of scale and translateZ to make it look like some words are flying through space.&lt;/p&gt;
&lt;p&gt;Lastly we&#39;ll use &lt;code&gt;rotateY&lt;/code&gt; to spin the letters of the tagline. Rotating around the Y-axis will require a bit of 3D work in the browser.&lt;/p&gt;
&lt;h2 id=&quot;svg%2C-html-and-css&quot; tabindex=&quot;-1&quot;&gt;SVG, HTML and CSS&lt;/h2&gt;
&lt;p&gt;In preparation for this example I made two SVG files for the &lt;a href=&quot;https://cssanimation.rocks/demo/starwars/images/star.svg&quot;&gt;Star&lt;/a&gt; and &lt;a href=&quot;https://cssanimation.rocks/demo/starwars/images/wars.svg&quot;&gt;Wars&lt;/a&gt; parts of the logo. Do feel free to grab them to use if you want to play along.&lt;/p&gt;
&lt;p&gt;The HTML for the demo is as follows:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;starwars-demo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/images/star.svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Star&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;star&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/images/wars.svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Wars&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wars&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;byline&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;byline&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;The Force Awakens&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A static image &lt;a href=&quot;https://cssanimation.rocks/demo/starwars/images/bg.jpg&quot;&gt;of some stars&lt;/a&gt; is used for the background. The font in the byline was tricky to find, so I&#39;ve referenced the web font &amp;quot;Lato&amp;quot; in this example.&lt;/p&gt;
&lt;p&gt;With some absolute positioning to center the content in the middle of the screen, we begin with this:&lt;/p&gt;
&lt;img src=&quot;https://cssanimation.rocks/images/posts/starwars/starwars.jpg&quot; /&gt;
&lt;h2 id=&quot;animating-the-star-and-wars&quot; tabindex=&quot;-1&quot;&gt;Animating the Star and Wars&lt;/h2&gt;
&lt;p&gt;We want the larger text to fade into view, while also starting larger and getting smaller over time. This is a good case for the &lt;code&gt;scale()&lt;/code&gt; transform. Let&#39;s use it on the word &amp;quot;Star&amp;quot; with these keyframes:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; star&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-0.75em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;20%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;89%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-1000em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are two properties that change over the course of this animation. The &lt;code&gt;opacity&lt;/code&gt; and &lt;code&gt;transform&lt;/code&gt;. The opacity change makes it start transparent, and fade away at the end so that we can loop the animation.&lt;/p&gt;
&lt;p&gt;The transform begins by setting the scale at &lt;code&gt;1.5&lt;/code&gt;. This means that the initial size of the text is 150% larger than normal. At 89%, we set the transform property to a scale of 1. This means that between 0% and 89%, the scale goes from 150% to 100%.&lt;/p&gt;
&lt;p&gt;The final &lt;code&gt;transformZ&lt;/code&gt; causes the words to zoom away quickly.&lt;/p&gt;
&lt;p&gt;We can apply these keyframes to the word &amp;quot;Star&amp;quot; like so:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.star&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; star 10s ease-out infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.wars&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; wars 10s ease-out infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;animation&lt;/code&gt; property here is specifying an animation called &lt;code&gt;star&lt;/code&gt;, and a duration of ten seconds. It applies the built-in &lt;code&gt;ease-out&lt;/code&gt; timing function, and tells it to repeat infinitely. We apply a similar rule for the word &amp;quot;Wars&amp;quot;.&lt;/p&gt;
&lt;h2 id=&quot;making-it-3d&quot; tabindex=&quot;-1&quot;&gt;Making it 3D&lt;/h2&gt;
&lt;p&gt;Using 3D transforms in CSS, whether translating along the Z-axis, or rotating around the Y and Z axes requires that we set a stage for the 3D. In HTML terms this means we create a container, and tell the browser that some 3D stuff is going to happen.&lt;/p&gt;
&lt;p&gt;We do this by adding the following to the &lt;code&gt;.starwars-demo&lt;/code&gt; div:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.starwars-demo&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;perspective&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 800px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; preserve3d&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These two properties tell the browser that the container&#39;s children should be positioned in 3D, rather than flat. &lt;a href=&quot;https://css-tricks.com/almanac/properties/t/transform-style/&quot;&gt;CSS Tricks&lt;/a&gt; goes into more detail on the property.&lt;/p&gt;
&lt;p&gt;Secondly, the &lt;code&gt;persective&lt;/code&gt; property tells the browser how &amp;quot;deep&amp;quot; the scene needs to be. In case we&#39;ve made it &lt;code&gt;800px&lt;/code&gt;. Smaller values create more &amp;quot;extreme&amp;quot; perspective effects as the scene is shorter.&lt;/p&gt;
&lt;p&gt;With that covered, we&#39;ll introduce the tagline.&lt;/p&gt;
&lt;h2 id=&quot;awaken-the-force&quot; tabindex=&quot;-1&quot;&gt;Awaken the Force&lt;/h2&gt;
&lt;p&gt;The tagline &amp;quot;The Force Awakens&amp;quot; appears in the trailer with each letter spinning into place. We can create this effect using the &lt;code&gt;rotateY&lt;/code&gt; transform. In this case we&#39;ve wrapped each of the letters in a &lt;code&gt;span&lt;/code&gt; element, so that we can apply animation to each letter.&lt;/p&gt;
&lt;p&gt;An issue I quickly discovered was that there isn&#39;t a straightforward way to animate each of the letters in the byline. My first approach was to manually wrap each letter in a &lt;code&gt;span&lt;/code&gt; tag. This worked but made the HTML a little messy. The current demo includes some JavaScript (thanks to &lt;a href=&quot;https://twitter.com/tadywankenobi&quot;&gt;Tady&lt;/a&gt; for the assist) that wraps each letter automatically in a &lt;code&gt;span&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We&#39;re going to apply an animation to each letter.&lt;/p&gt;
&lt;p&gt;First, the keyframes:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; spin-letters&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 10%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;90deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;30%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;70%, 86%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;95%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To begin with, the letters are rotated 90 degrees, then by 70% through the animation, they&#39;ve been animated to face the viewer.&lt;/p&gt;
&lt;p&gt;We can apply this set of keyframes to each span like so:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.byline span&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin-letters 10s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.byline&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; move-byline 10s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result is each of the &lt;code&gt;span&lt;/code&gt; containers that hold each letter will fade and spin slowly into place, before fading away at the end of the animation.&lt;/p&gt;
&lt;p&gt;Putting it together we have the &lt;a href=&quot;http://codepen.io/donovanh/pen/pJzwEw?editors=110&quot;&gt;finished demo&lt;/a&gt;.&lt;/p&gt;
&lt;p data-height=&quot;468&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;pJzwEw&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; class=&quot;codepen&quot;&gt;&lt;/p&gt;
&lt;script async=&quot;&quot; src=&quot;https://assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;callout&quot;&gt;
  &lt;p&gt;This is an excerpt from the course, &lt;a href=&quot;https://cssanimation.rocks/courses/animation-101/&quot;&gt;CSS Animation 101&lt;/a&gt;. For a limited time you can &lt;em&gt;pay what you want&lt;/em&gt;. &lt;a href=&quot;https://cssanimation.rocks/courses/animation-101/&quot;&gt;Check it out!&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
</content>
  </entry><entry>
    <title>Why animate?</title>
    <link href="https://cssanimation.rocks/why-animate/"/>
    <updated>2016-01-01T00:00:00Z</updated>
    <id>https://cssanimation.rocks/why-animate/</id>
    <content type="html">&lt;p&gt;Staring into the flickering flames of a fire, watching the waves of the sea lap against a shore, catching a sharp glimpse of a tiger about to pounce, the world is movement.&lt;/p&gt;
&lt;p&gt;We are really good at noticing and reacting to movement. It&#39;s hardwired into our brains and is an important part of how we understand the world around us.&lt;/p&gt;
&lt;p&gt;When we sit down to design a web site, we are creating something that will communicate with our visitors. Animation is one of the ways we can do this.&lt;/p&gt;
&lt;h2 id=&quot;communication&quot; tabindex=&quot;-1&quot;&gt;Communication&lt;/h2&gt;
&lt;p&gt;Often when designing web sites we think about the content, the layout, styles, fonts and colors. But we can also communicate through movement. Rather than consider animation something separate in the design process, the way things move is another facet in our designs that works and communicates alongside everything else.&lt;/p&gt;
&lt;p&gt;All these things add up to create our brand and an experience we hope will be worthwhile.&lt;/p&gt;
&lt;p&gt;We hope that our designs communicate our content effectively, communicate our great attention to detail, and leave the visitors happy. Since our visitors are great at noticing and understanding movement, animation is an important and powerful tool.&lt;/p&gt;
&lt;h2 id=&quot;humble-beginnings&quot; tabindex=&quot;-1&quot;&gt;Humble beginnings&lt;/h2&gt;
&lt;p&gt;A simple example of animation we see everywhere is the hover effect. It seems strange to marvel at this simple concept now but when it was first introduced, it was quite a big deal.&lt;/p&gt;
&lt;p&gt;Back when the web was first taking shape, we had documents connected through hyperlinks. These links, in order to communicate their difference from the text around them, were given a blue color and underlined. The cursor would also change to a &lt;code&gt;pointer&lt;/code&gt; style.&lt;/p&gt;
&lt;p&gt;When clicked they would change to purple to show that the link was active, or later that it had been visited. The colors were used as a way to communicate the status of the link. Things were pretty good.&lt;/p&gt;
&lt;p&gt;Then along came CSS. In &lt;a href=&quot;http://www.w3.org/TR/WD-CSS2-971104/cover.html&quot; title=&quot;w3 specification for CSS 2&quot;&gt;early 1998&lt;/a&gt;, the &lt;code&gt;:hover&lt;/code&gt; selector arrived. Suddenly we could do so much more. Rather than rely on a sudden cursor change, we could apply styles to the link itself when the cursor hovered in front of it.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; red&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this small change, we were communicating more. List of links became interactive playgrounds as we gleefully danced our cursors around, getting immediate feedback from the link colors.&lt;/p&gt;
&lt;p&gt;It wasn&#39;t just for fun though. The change in color adds more information about what is happening on screen. We humans, being great at noticing movement or when things change, benefit when this extra information. But we can do more.&lt;/p&gt;
&lt;h2 id=&quot;conveying-more-information&quot; tabindex=&quot;-1&quot;&gt;Conveying more information&lt;/h2&gt;
&lt;p&gt;Rather than stop at changing the color, we can add animation too. Animating a color change gives our eyes even more opportunity to notice the change, as it draws it out over a longer period of time. An animated change is easier to notice than a sudden change.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a {
  transition: color 0.2s;
}
a:hover {
  color: red;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this we add a transition to the anchor CSS. When a link is hovered over, the browser will animate the color of the text from blue (or purple) to red over the course of 0.2 seconds.&lt;/p&gt;
&lt;h2 id=&quot;taking-it-further&quot; tabindex=&quot;-1&quot;&gt;Taking it further&lt;/h2&gt;
&lt;p&gt;It might not seem like much but even these simple tools open up a world of communication that we can use to add life to our designs.&lt;/p&gt;
&lt;p&gt;With the ability to convey information through motion, we can draw attention to part of our pages that have changed, signal the arrival or removal of content, show our visitors what to look at next and much more.&lt;/p&gt;
&lt;p&gt;Some ways animation can add value to a design:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Highlighting interactive content&lt;/li&gt;
&lt;li&gt;Adding or removing content&lt;/li&gt;
&lt;li&gt;Telling a story&lt;/li&gt;
&lt;li&gt;Calling attention&lt;/li&gt;
&lt;li&gt;Credibility&lt;/li&gt;
&lt;li&gt;Branding and fun&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;highlighting-interactive-content&quot; tabindex=&quot;-1&quot;&gt;Highlighting interactive content&lt;/h3&gt;
&lt;p&gt;Hovering links is one way animation can add value, but we can go further. Tooltips, changing design styles and other visual changes can make your pages feel more alive and prompt visitors to select, press or otherwise interact with your content. Draggable areas can expand or highlight on touch, black and white images can turn to color and more.&lt;/p&gt;
&lt;h3 id=&quot;adding-or-removing-content&quot; tabindex=&quot;-1&quot;&gt;Adding or removing content&lt;/h3&gt;
&lt;p&gt;If content on a page suddenly vanishes or appears, we might notice. But that&#39;s all we know. We don&#39;t know where it went, and perhaps why. This is an opportunity to add a little animation.&lt;/p&gt;
&lt;p&gt;Adding an extra line to a todo list, sliding in a control panel or minimising content to a corner of the page all benefit from animation. By showing where things come from and where they go to, our visitors maintain a connection with the page and better understand how it works.&lt;/p&gt;
&lt;h3 id=&quot;telling-a-story&quot; tabindex=&quot;-1&quot;&gt;Telling a story&lt;/h3&gt;
&lt;p&gt;We&#39;re not limited to text or even static images in our web pages. By moving elements around, adding new elements or removing them you can take your visitors on a journey and leave them better informed.&lt;/p&gt;
&lt;p&gt;The homepage over at &lt;a href=&quot;http://mailchimp.com/&quot;&gt;Mailchimp&lt;/a&gt; is a good example of this. In the center of the screen they&#39;ve used several HTML elements and some CSS animations to explain how to build emails.&lt;/p&gt;
&lt;p&gt;Whereas we might have created something like this with Flash not that long ago, we can now do so without relying on plugins and while keeping our sites fast, accessible and responsive.&lt;/p&gt;
&lt;h3 id=&quot;calling-attention&quot; tabindex=&quot;-1&quot;&gt;Calling attention&lt;/h3&gt;
&lt;p&gt;We&#39;re great at noticing when things change visually. This trait is something we can use to call attention to specific areas. A common use for this could be when some content is updated on the page and we make it flash or change color.&lt;/p&gt;
&lt;p&gt;We can take this further and have our sign up button shake a little when the page first loads as if to say &amp;quot;hey, I&#39;m important&amp;quot;, or we could have a suggested article fly in from the side of the screen when the visitor reaches the end of the previous one.&lt;/p&gt;
&lt;p&gt;Done with care, animation is a very powerful way to draw attention to what we want people to notice.&lt;/p&gt;
&lt;h3 id=&quot;credibility&quot; tabindex=&quot;-1&quot;&gt;Credibility&lt;/h3&gt;
&lt;p&gt;Something less often considered is the effect good animation can have on a visitor&#39;s confidence in our site. If you notice the interactions with your operating system, there&#39;s a lot of subtle animation. Things fade in or out, move to and from task bars and convey a polish that helps you understand the computer.&lt;/p&gt;
&lt;p&gt;When we design websites we often forget this, and instead create an experience that feel flat. Animation can make your site&#39;s interactions feel better.&lt;/p&gt;
&lt;p&gt;In a &lt;a href=&quot;https://medium.com/@michaelvillar/improve-the-payment-experience-with-animations-3d1b0a9b810e&quot; title=&quot;Improve the payment experience with animations&quot;&gt;post on Medium.com&lt;/a&gt;, Michaël Villar explains how Stripe&#39;s checkout process uses animation to help the user both in their interaction with the checkout flow but also to instill confidence.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;The over-the-top polished feel of this animation adds to the overall user experience, by conveying a level of perfection and attention to detail that you can’t help but trust&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With the right style, animations can make the user feel like they&#39;re using a polished, modern UI.&lt;/p&gt;
&lt;h3 id=&quot;branding-and-fun&quot; tabindex=&quot;-1&quot;&gt;Branding and fun&lt;/h3&gt;
&lt;p&gt;When &lt;a href=&quot;http://yahoo.com/&quot; title=&quot;Yahoo&quot;&gt;Yahoo!&lt;/a&gt; went through a large rebranding in 2013, they added subtle animations to each of their website logos. Aiming to convey a feeling of fun, they were created both draw attention to the change and get people talking about it.&lt;/p&gt;
&lt;p&gt;The site doesn&#39;t seem to have them any more, but you can find  examples of the animations over on the &lt;a href=&quot;http://astronautlove.tv/yahoo-rebrand-yahoo/&quot; title=&quot;Examples of the Yahoo! logos being animated&quot;&gt;Astronaut Love website&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When Stripe uses animation, they do so with a level of polish that people (and developers considering using their service) associate with their name. In both cases, the animation helps draw attention to and bolster their brand.&lt;/p&gt;
&lt;p&gt;Animation can also be fun. On &lt;a href=&quot;http://hop.ie/&quot; title=&quot;Hop.ie&quot;&gt;Hop.ie&lt;/a&gt;, I created a &amp;quot;bouncer&amp;quot; character that would bounce in from the left to act as a logo. While keeping the site&#39;s design very simple, this bouncer acts as an anchor that links back to the home page. It doesn&#39;t need animation, but I find adding a little lifts the tone. No harm in having a bit of fun.&lt;/p&gt;
&lt;h2 id=&quot;great-power%2C-great-responsibility&quot; tabindex=&quot;-1&quot;&gt;Great power, great responsibility&lt;/h2&gt;
&lt;p&gt;Animation is a powerful tool. Much like how we find it easy to stare into the flickering of a burning fire, we find animation difficult to ignore. Some people even find it impossible to ignore.&lt;/p&gt;
&lt;p&gt;When considering how you use animation in your designs, keep in mind that it&#39;s a communication tool. It should be used sparingly and never get in the way of the content or interactions.&lt;/p&gt;
&lt;p&gt;It&#39;s unpleasant to try to listen to multiple people speaking at once, or to try to focus in a loud busy environment. Too much animation creates a visual noise that distracts and makes life harder for your visitors. With that in mind, always try to pare back the use of animation and keep it subtle.&lt;/p&gt;
&lt;h2 id=&quot;why-animate-now%3F&quot; tabindex=&quot;-1&quot;&gt;Why animate now?&lt;/h2&gt;
&lt;p&gt;There&#39;s never been a better time to bring animation into your web design process. Browsers are getting better, devices are becoming more powerful, and we are getting better tools to help create animation.&lt;/p&gt;
&lt;p&gt;Using animation takes judgement. If you want to be great at using animation to help your content stand out, improve conversions, or generally improve your brand, it&#39;s time to start.&lt;/p&gt;
</content>
  </entry><entry>
    <title>New course &amp;amp; competition</title>
    <link href="https://cssanimation.rocks/levelup-competition/"/>
    <updated>2017-03-01T00:00:00Z</updated>
    <id>https://cssanimation.rocks/levelup-competition/</id>
    <content type="html">&lt;p&gt;Today&#39;s a big day. We passed &lt;a href=&quot;https://twitter.com/cssanimation&quot;&gt;&lt;strong&gt;5,000&lt;/strong&gt; Twitter followers&lt;/a&gt; (hi everyone!), and I have news for you about a new course I&#39;m launching very soon.&lt;/p&gt;
&lt;p&gt;I&#39;d like to give you the opportunity to be one of the very first to enjoy the course, &lt;a href=&quot;https://cssanimation.rocks/levelup-competition/#id-buy-that-for-a-dollar&quot;&gt;for just &lt;strong&gt;$1&lt;/strong&gt;&lt;/a&gt;!&lt;/p&gt;
&lt;h2 id=&quot;practical-and-useful-lessons&quot; tabindex=&quot;-1&quot;&gt;Practical and useful lessons&lt;/h2&gt;
&lt;p&gt;It&#39;s almost exactly 2 years since I launched &lt;a href=&quot;https://cssanimation.rocks/courses/animation-101/&quot;&gt;CSS Animation 101&lt;/a&gt; as an email-based intro to CSS animation. More than 2,000 of you have enjoyed the course and I&#39;ve had loads of great feedback and suggestions.&lt;/p&gt;
&lt;p&gt;Many people have been in touch to ask how they should apply these skills to real projects.&lt;/p&gt;
&lt;p&gt;To answer this I&#39;m creating a new course that will focus on the practical step-by-step work of creating an animated landing page. You&#39;ll learn how to apply your technical knowledge and get expert advice on what to do and what to avoid.&lt;/p&gt;
&lt;h2 id=&quot;trying-something-new&quot; tabindex=&quot;-1&quot;&gt;Trying something new&lt;/h2&gt;
&lt;p&gt;This time I&#39;ll be trying something new. I&#39;d like you all to join me on the creative journey of building and recording the course. To do this, I&#39;ll be releasing each module one at a time.&lt;/p&gt;
&lt;p&gt;The first module will be arriving at the end of March. After that, I&#39;ll be listening to your thoughts, and bringing out a new module every few weeks. Each module builds on the last and works toward creating a complete, working animated landing page.&lt;/p&gt;
&lt;p&gt;Topics we&#39;ll be covering include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Build an impressive animation header to show off your brand&lt;/li&gt;
&lt;li&gt;Make designs feel alive with touch and hover animations&lt;/li&gt;
&lt;li&gt;Trigger custom animations when scrolling&lt;/li&gt;
&lt;li&gt;Use animation to grab attention&lt;/li&gt;
&lt;li&gt;Build an animated content carousel&lt;/li&gt;
&lt;li&gt;Putting together your own animation library using Sass&lt;/li&gt;
&lt;li&gt;And more modules added over time (your feedback counts)!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each module will come with downloadable code you can use &lt;em&gt;right away&lt;/em&gt; on your projects. Once you enrol, you&#39;ll get lifetime access to all modules as well as any future modules I add.&lt;/p&gt;
&lt;h2 id=&quot;social-learning&quot; tabindex=&quot;-1&quot;&gt;Social learning&lt;/h2&gt;
&lt;p&gt;As well as video lessons, downloadable code and cheatsheets - you&#39;ll also get access to the exclusive CSS Animation Rocks Slack channel. Share your work, questions and ideas and get help as you learn CSS Animation.&lt;/p&gt;
&lt;h2 id=&quot;sneak-peak&quot; tabindex=&quot;-1&quot;&gt;Sneak peak&lt;/h2&gt;
&lt;p&gt;Want an early glimpse of the course? You can &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;see the Super-secret pre-launch course page now&lt;/a&gt; for more info. Sshhh! (I&#39;m kidding, tell everyone!)&lt;/p&gt;
&lt;h2 id=&quot;i&#39;d-buy-that-for-a-dollar&quot; tabindex=&quot;-1&quot;&gt;I&#39;d buy that for a dollar&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Shut up and take my money&lt;/em&gt; you say? Just a minute! How much would you want to pay for such a useful, professional course? $1000? $300? How about &lt;strong&gt;$1&lt;/strong&gt;? 😲&lt;/p&gt;
&lt;p&gt;This Friday I&#39;ll be selecting by random 20 lucky people to buy this course for just $1.&lt;/p&gt;
&lt;p&gt;There are three ways you can win. Pick one, or you can maximise your chances by doing all three:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure you&#39;re &lt;a href=&quot;https://twitter.com/cssanimation&quot;&gt;following on Twitter&lt;/a&gt; and &lt;a href=&quot;http://twitter.com/intent/tweet?url=http%3A%2F%2Fcourses.cssanimation.rocks%2Fp%2Flevel-up&amp;amp;text=This%20course%20looks%20amazing!%20Level%20up%20your%20CSS%20animation%20skills%20with%20%40CSSAnimation%20https%3A%2F%2Fcssanimation.rocks%2Fimages%2Fcourses%2Flevelup%2Fcover2.png&quot;&gt;give the course a mention&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OR&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.facebook.com/cssanimation&quot;&gt;Like the Facebook page&lt;/a&gt; and &lt;a href=&quot;https://www.facebook.com/dialog/feed?app_id=184683071273&amp;amp;link=http%3A%2F%2Fcourses.cssanimation.rocks%2Fp%2Flevel-up&amp;amp;picture=https%3A%2F%2Fcssanimation.rocks%2Fimages%2Fcourses%2Flevelup%2Fcover2.png&amp;amp;name=New%20CSS%20Animation%20Rocks%20course&amp;amp;caption=%20&amp;amp;description=Learn%20how%20to%20apply%20the%20theory%20of%20CSS%20animations%20in%20this%20video%20course%20from%20CSS%20Animation%20Rocks.&amp;amp;redirect_uri=http%3A%2F%2Fwww.facebook.com%2F&quot;&gt;shout it out on the Facebooks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OR&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure you&#39;ve signed up to the &lt;a href=&quot;https://weekly.cssanimation.rocks/&quot;&gt;CSS Animation Weekly newsletter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Be quick! This competition closes on Friday, 3rd March at 12pm GMT. Winners will be contacted shortly after.&lt;/p&gt;
&lt;p&gt;I&#39;m looking forward to seeing how you all get on with this new course and excited to see the amazing animations you create.&lt;/p&gt;
</content>
  </entry><entry>
    <title>Animating your hero header</title>
    <link href="https://cssanimation.rocks/animating-hero-header/"/>
    <updated>2017-03-12T00:00:00Z</updated>
    <id>https://cssanimation.rocks/animating-hero-header/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;If you&#39;ve ever arrived on a website and been greeted by a large image or video, and some titles on top, then you&#39;ve encountered the &amp;quot;Hero Header&amp;quot;. It&#39;s a popular way to introduce a website, and can be a great opportunity to help people quickly understand what it is your site does.&lt;/p&gt;
&lt;p&gt;For many visitors it&#39;ll be their first impression of your brand, so you&#39;ll want to make the most of this moment to shine.&lt;/p&gt;
&lt;p&gt;Here&#39;s what we&#39;ll be putting together.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;PpbvZB&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (staggered and cubic bezier and wedge)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/PpbvZB/&quot;&gt;Landing page with animated foreground elements (staggered and cubic bezier and wedge)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;standing-out-from-the-rest&quot; tabindex=&quot;-1&quot;&gt;Standing out from the rest&lt;/h2&gt;
&lt;p&gt;We can use animation to add polish to that first moment when the content appears, as well as use it to control the order in which information appears and draw the eye to what matters.&lt;/p&gt;
&lt;p&gt;In this tutorial we&#39;ll animate in the content on top, and take the opportunity to experiment more with bouncy timing functions, animation choreography and creating reusable sets of keyframes.&lt;/p&gt;
&lt;h2 id=&quot;introducing-the-titles&quot; tabindex=&quot;-1&quot;&gt;Introducing the titles&lt;/h2&gt;
&lt;p&gt;Here&#39;s what we&#39;re starting with.&lt;/p&gt;
&lt;p&gt;It&#39;s got a nice background image, some titles and a bit call-to-action button.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;NpbyJP&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with background image&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/NpbyJP/&quot;&gt;Landing page with background image&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;making-it-bounce&quot; tabindex=&quot;-1&quot;&gt;Making it bounce&lt;/h2&gt;
&lt;p&gt;Like in the choreography you see in stage performances and dances, we&#39;re going to think about how all the various pieces of content in our hero header move together. We could have the elements slide in to place like the background image, which would show a nice connectedness between the elements. Let&#39;s also take it a little further by making each of the elements seem to pop out of the screen.&lt;/p&gt;
&lt;p&gt;To begin we&#39;ll create some &lt;code&gt;keyframes&lt;/code&gt; for the animation. Within the &lt;code&gt;keyframes&lt;/code&gt; container, we want &amp;quot;0%&amp;quot; and &amp;quot;100%&amp;quot; frames, representing the beginning and end states of the animation.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; pop-in&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-4rem&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Initially the content will be invisible, so we&#39;re setting &lt;code&gt;opacity&lt;/code&gt; to 0. We&#39;ll also use a &lt;code&gt;transform&lt;/code&gt; to &lt;code&gt;translate&lt;/code&gt; the position of the content up by 4em. Lastly we&#39;re adding a new transform. We&#39;re scaling the size down to 0.8 in the starting frame.&lt;/p&gt;
&lt;p&gt;This means that when the animation starts the elements will be a little smaller, and by the end will have animated to their normal size. Let&#39;s see how we apply this to the content.&lt;/p&gt;
&lt;h2 id=&quot;moving-the-elements&quot; tabindex=&quot;-1&quot;&gt;Moving the elements&lt;/h2&gt;
&lt;p&gt;We can now apply these keyframes to our content. However rather than adding an &lt;code&gt;animation&lt;/code&gt; property to each element one at a time, let&#39;s take this opportunity to set up a reusable class for the animation. If we create a new class called &lt;code&gt;animate-pop-in&lt;/code&gt;, we can then have this apply the animation more efficiently.&lt;/p&gt;
&lt;p&gt;To get started, in the HTML, we add this class to each of the content items we want to animate.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;... other HTML ...
&amp;lt;section class=&lt;span class=&quot;token string&quot;&gt;&quot;header-content&quot;&lt;/span&gt;&gt;
  &amp;lt;img class=&lt;span class=&quot;token string&quot;&gt;&quot;rocky-dashed animate-pop-in&quot;&lt;/span&gt; src=&lt;span class=&quot;token string&quot;&gt;&quot;images/rocky-dashed.svg&quot;&lt;/span&gt;&gt;
  &amp;lt;h1 class=&lt;span class=&quot;token string&quot;&gt;&quot;header-title animate-pop-in&quot;&lt;/span&gt;&gt;Your awesome landing page&amp;lt;/h1&gt;
  &amp;lt;h3 class=&lt;span class=&quot;token string&quot;&gt;&quot;header-subtitle animate-pop-in&quot;&lt;/span&gt;&gt;A useful start for your projects&amp;lt;/h3&gt;
  &amp;lt;p class=&lt;span class=&quot;token string&quot;&gt;&quot;header-button animate-pop-in&quot;&lt;/span&gt;&gt;&amp;lt;a href=&lt;span class=&quot;token string&quot;&gt;&quot;#calls-to-action&quot;&lt;/span&gt; class=&lt;span class=&quot;token string&quot;&gt;&quot;button&quot;&lt;/span&gt;&gt;Get started today&amp;lt;/a&gt;&amp;lt;/p&gt;
&amp;lt;/section&gt;
... other HTML ...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;ve added the &lt;code&gt;animate-pop-in&lt;/code&gt; class to the image, headings and paragraph text. Now we can make use of that in our CSS. Here&#39;s what we add to our CSS.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.animate-pop-in&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pop-in .6s ease-out forwards&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This applies the animation &lt;code&gt;pop-in&lt;/code&gt; to every element. It&#39;s making them appear with a duration of .6 seconds, and using the &lt;code&gt;ease-out&lt;/code&gt; timing function.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note: Hover and press &amp;quot;Rerun&amp;quot; to see the animation!&lt;/strong&gt;&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;bqgywx&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (no bg movement + not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/bqgywx/&quot;&gt;Landing page with animated foreground elements (no bg movement + not staggered)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It&#39;s a start! But we can do better.&lt;/p&gt;
&lt;h2 id=&quot;choreography&quot; tabindex=&quot;-1&quot;&gt;Choreography&lt;/h2&gt;
&lt;p&gt;Currently the content elements are popping in while the page is still blank. When we built our background animation, we made use of the &lt;code&gt;animation-delay&lt;/code&gt; property. This meant the background waited for .5 seconds before the animation began.&lt;/p&gt;
&lt;p&gt;Let&#39;s add some delays to our content items so that they show up after the background has started to appear.&lt;/p&gt;
&lt;p&gt;Before we start adding delays, we set out which elements we&#39;re going to style.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.rocky-dashed&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-title&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-subtitle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These 4 elements will need to appear, one at a time. Thankfully we don&#39;t need to put in the entire &lt;code&gt;animation&lt;/code&gt; property for each, as these elements already have the &lt;code&gt;animate-pop-in&lt;/code&gt; class. We&#39;ll just specify a delay on each one. Since the background animation takes about a second to get going, let&#39;s start these off with a delay of 1 second and increase it for each element.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.rocky-dashed&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-title&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.2s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-subtitle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.4s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.6s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We also need to set these elements to be invisible on load, to avoid the flash where they&#39;re visible then they animate after a delay. Set the opacity on the &amp;quot;animate-pop-in&amp;quot; element.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.animate-pop-in&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pop-in .6s ease-out forwards&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So let&#39;s see the result. We&#39;ve added a delay that starts at 1 second, then each item waits a further .2 seconds before starting. When we look at the result we see the animations staggered.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;yMgWVW&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (no bg movement + staggered1)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/yMgWVW/&quot;&gt;Landing page with animated foreground elements (no bg movement + staggered1)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It might just be my opinion but I reckon these seem to be appearing just a little bit late. Let&#39;s go back through and change the numbers so they start at .6s instead.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.rocky-dashed&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .6s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-title&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .8s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-subtitle&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1.1s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On second thoughts, let&#39;s make that last item, the &lt;code&gt;header-button&lt;/code&gt; appear a little more closely with just a .1 second gap. It should now all feel a bit tighter.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;ryWgaV&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (no bg movement + staggered2)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/ryWgaV/&quot;&gt;Landing page with animated foreground elements (no bg movement + staggered2)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;That&#39;s better. It&#39;s a good idea to take time to tweak things like animation delays and timing functions by eye. Sometimes an animation won&#39;t feel right and it might just be a question of messing around with the timings until it all works together.&lt;/p&gt;
&lt;p&gt;So, now we have a staggered animation. It&#39;s looking pretty good, but the way the animation ends feels a little flat. Let&#39;s see if we can bring some life to this little animation with a more bouncy timing function.&lt;/p&gt;
&lt;h2 id=&quot;bounciness&quot; tabindex=&quot;-1&quot;&gt;Bounciness&lt;/h2&gt;
&lt;p&gt;Time to replace that old &lt;code&gt;ease-out&lt;/code&gt; timing function with something more interesting. Over on &lt;a href=&quot;http://cubic-bezier.com/&quot;&gt;Cubic-Bezier.com&lt;/a&gt; we&#39;ll create a curve that starts fast but then shoots right past the top and settles back to the finishing point. Place the first point on the left axis near the top to give it that fast start, then the second point above the top line. The resulting curve should be a long steep arc that tapers back at the end.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/levelup/public/images/01/bezier02.png&quot; alt=&quot;A bezier curve with points 0, .9, .3, 1.2&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Taking the coordinates and putting them into our animation property now looks like this.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pop-in .6s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.9&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.3&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1.2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; forwards&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&#39;s see how that looks.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;mWRYmp&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (no bg movement+ staggered and cubic bezier)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/mWRYmp/&quot;&gt;Landing page with animated foreground elements (no bg movement+ staggered and cubic bezier)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It&#39;s starting to look a lot better now.&lt;/p&gt;
&lt;h2 id=&quot;pieces-working-together&quot; tabindex=&quot;-1&quot;&gt;Pieces working together&lt;/h2&gt;
&lt;p&gt;The purpose of this choreography is to not only to look cool, but to draw attention to what we want our visitors to see. In this case it&#39;s straightforward, we want people to see the title and then have their attention drawn to the big &amp;quot;call to action&amp;quot; button in the middle.&lt;/p&gt;
&lt;p&gt;There&#39;s a second goal here though, and that&#39;s to let people know that there&#39;s more content further down the page. We&#39;re going to help draw attention to that using a chevron at the bottom , but we can add a subtle animation to the header also. Let&#39;s try our hand at a rotate &lt;code&gt;transform&lt;/code&gt; by animating that big white wedge at the bottom of the screen.&lt;/p&gt;
&lt;h2 id=&quot;animating-the-wedge&quot; tabindex=&quot;-1&quot;&gt;Animating the wedge&lt;/h2&gt;
&lt;p&gt;As before we&#39;ll create the &lt;code&gt;keyframes&lt;/code&gt; for this new animation.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; rotate-up&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-4deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&#39;ll notice there&#39;s no &amp;quot;0%&amp;quot; this time. That&#39;s because it&#39;s optional. You can choose to leave out either the starting or even the ending keyframe and the browser will infer it based on the styles given to the element. In this case, it&#39;ll go from having no transform, to being rotated. We apply this by making a couple of changes to our &lt;code&gt;header:after&lt;/code&gt; block.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;header:after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rotate-up .5s .5s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.5&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; forwards&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #F9FCFF&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 40rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -5%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 90%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First we add the &lt;code&gt;animation&lt;/code&gt; property, giving it the animation name of &lt;code&gt;rotate-up&lt;/code&gt;. I&#39;ve decided to make the duration just .5 seconds this time. If it&#39;s longer, it&#39;ll still be moving when the other content is appearing and that could confuse the flow. We&#39;d like this to be a subtle animation that doesn&#39;t distract from the main content. We&#39;ll have it delayed for .5s and use the same timing function as the background image.&lt;/p&gt;
&lt;p&gt;Lastly we want this to begin without any &lt;code&gt;transform&lt;/code&gt;, so we remove that line. It should now use the &lt;code&gt;rotate-up&lt;/code&gt; keyframes to rotate from no transform, to -4 degrees.&lt;/p&gt;
&lt;p&gt;As a last minute bonus, I&#39;ve added some animation to the background image too. Really brings it all together! Check out the  result.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;PpbvZB&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (staggered and cubic bezier and wedge)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/PpbvZB/&quot;&gt;Landing page with animated foreground elements (staggered and cubic bezier and wedge)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot; tabindex=&quot;-1&quot;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;In this tutorial we have learned how to create and apply an animation to a class of elements, then use the &lt;code&gt;animation-delay&lt;/code&gt; property to choreograph them. We&#39;ll be able to reuse this &lt;code&gt;animate-pop-in&lt;/code&gt; class elsewhere without adding any extra CSS code to our project, essentially making it the beginning of our own animation library.&lt;/p&gt;
&lt;p&gt;You may have noticed the lack of scroll cue, and an issue where the image might be half-loaded when the animation starts. Don&#39;t worry, you can find these and many more answers in &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;the full course&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;take-your-skills-to-the-next-level&quot; tabindex=&quot;-1&quot;&gt;Take your skills to the next level&lt;/h3&gt;
&lt;p&gt;This is part of the new course, &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;Level Up your CSS Animation Skills&lt;/a&gt;. Build the ultimate animated landing page. Enrol today and save 58%!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cssanimation.rocks/animating-hero-header/&quot; class=&quot;button button-primary&quot;&gt;I want this!&lt;/a&gt;&lt;/p&gt;
</content>
  </entry><entry>
    <title>Course update: Module 1 videos</title>
    <link href="https://cssanimation.rocks/course-update-1/"/>
    <updated>2017-03-17T00:00:00Z</updated>
    <id>https://cssanimation.rocks/course-update-1/</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;Level up your CSS animation skills&lt;/a&gt; just got better with all new videos for Module 1, &amp;quot;Build an animated hero header&amp;quot;.&lt;/p&gt;
&lt;p&gt;Enjoy professionally produced videos and learn how to bring your static web sites to life. This update brings you &lt;strong&gt;over 45 minutes of practical, step by step lessons&lt;/strong&gt; - and it&#39;s just the start.&lt;/p&gt;
&lt;p&gt;Here&#39;s a taste of what to expect:&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
  &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/0jhDAVkdsAI?modestbranding=1&amp;cc_load_policy=0&amp;iv_load_policy=3&amp;vq=hd720&amp;rel=0&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;p&gt;Module #1 includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What is a hero header?&lt;/li&gt;
&lt;li&gt;Why should we use CSS to animate it?&lt;/li&gt;
&lt;li&gt;How to always create smooth animations&lt;/li&gt;
&lt;li&gt;How to create sets of keyframes&lt;/li&gt;
&lt;li&gt;Creating your own cubic-bezier timing functions&lt;/li&gt;
&lt;li&gt;Controlling animations with &amp;quot;animation-play-state&amp;quot;&lt;/li&gt;
&lt;li&gt;Reusing keyframes in multiple animations&lt;/li&gt;
&lt;li&gt;and more!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;next-steps&quot; tabindex=&quot;-1&quot;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;Enrol here&lt;/a&gt; and get the special pre-launch discount!&lt;/p&gt;
&lt;p&gt;I&#39;m working on some fantastic downloads and cheat sheets for the module, which will arrive soon. Be sure to &lt;a href=&quot;https://twitter.com/cssanimation&quot;&gt;follow on Twitter&lt;/a&gt; for more updates!&lt;/p&gt;
</content>
  </entry><entry>
    <title>Build an awesome Hero Header</title>
    <link href="https://cssanimation.rocks/build-hero-header/"/>
    <updated>2017-03-20T00:00:00Z</updated>
    <id>https://cssanimation.rocks/build-hero-header/</id>
    <content type="html">&lt;p&gt;When people arrive on your homepage you have mere seconds to impress them, explain what you&#39;re about and convince them to stick around. This is an important moment yet most sites miss the opportunity to impress and connect with their visitors.&lt;/p&gt;
&lt;p&gt;Let&#39;s make sure your hero header stands head and shoulders above the rest.&lt;/p&gt;
&lt;h2 id=&quot;what-to-include-in-your-hero-header&quot; tabindex=&quot;-1&quot;&gt;What to include in your Hero Header&lt;/h2&gt;
&lt;p&gt;There are all sorts of ways you can tackle your hero header. You might want it to take over the entire page, maybe it needs to showcase new products, or explain in one short sentence what your brand does. There are some ingredients most hero headers share. These might include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An eye catching headline&lt;/li&gt;
&lt;li&gt;A call to action&lt;/li&gt;
&lt;li&gt;Large striking background image or video&lt;/li&gt;
&lt;li&gt;An embedded explainer video or animation&lt;/li&gt;
&lt;li&gt;A carousel showcasing featured content&lt;/li&gt;
&lt;li&gt;Company branding - logo or slogan&lt;/li&gt;
&lt;li&gt;Branding and navigation&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cssanimation.rocks/animating-hero-header/&quot;&gt;Animation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&#39;s go through each of these and see how each can be built into our hero header section.&lt;/p&gt;
&lt;h2 id=&quot;the-headline&quot; tabindex=&quot;-1&quot;&gt;The headline&lt;/h2&gt;
&lt;p&gt;We start with the headline. This is likely the first thing your visitors will read. It needs to be easy to understand while also conveying the right message. In this example, Mailchimp uses the space to explain that their service helps you &amp;quot;Send better email&amp;quot; and &amp;quot;Sell more stuff&amp;quot;. This is short and easy to read but also lets me know just what it is Mailchimp does.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/mailchimp.png&quot; alt=&quot;Mailchimp header&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;getting-the-style-right&quot; tabindex=&quot;-1&quot;&gt;Getting the style right&lt;/h3&gt;
&lt;p&gt;When making your text easy to understand, it also needs to be clear. Again in the previous example the dark text is set against a plain white background. There&#39;s no way to miss that headline! A large, bold font helps too. In this example from Tito we see the text set against a background image. The image is faded a little to let the text stand out better.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/tito.png&quot; alt=&quot;Tito header&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If you&#39;re using background images it&#39;s usually a good idea to go for large white text as it tends to be easier to read than dark text. Here are some &lt;a href=&quot;https://designmodo.com/design-type-photo/&quot;&gt;handy tips on helping your text stand out on an image&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;the-call-to-action&quot; tabindex=&quot;-1&quot;&gt;The call to action&lt;/h2&gt;
&lt;p&gt;Once you&#39;ve established your initial message through the big, eye catching headline the next step is to guide your visitor into the action you want them to carry out. This might be clicking a &amp;quot;sign up&amp;quot; button, encouraging them to see your products or projects, or leave their email with you. This usually takes the form of a button or a form (with a button) and is called the &amp;quot;call to action&amp;quot;.&lt;/p&gt;
&lt;p&gt;When designing your call to action you need to make sure it stands out visually. This could mean using a brand colour as the background, making it large or placing it in a prominent position on the screen. Front and center just under the headline is a popular choice, but it doesn&#39;t have to be. A good highlight colour can make a call to action stand out even when it&#39;s up in the top right corner, like on this example from Each&amp;amp;Other.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/eachother.png&quot; alt=&quot;Each&amp;amp;Other header&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Once you have it in place, the next thing to consider is your choice of words. Think in terms of &lt;em&gt;actions&lt;/em&gt;. What would you like your customer to do? Phrases such as &amp;quot;Get started&amp;quot;, &amp;quot;Download now&amp;quot; or &amp;quot;Sign up&amp;quot; are all very action oriented and help your visitor understand what the button means. Try to avoid terms like &amp;quot;Submit&amp;quot; or &amp;quot;Go&amp;quot;. A vague phrase here can slow people down, and what you really want is for your happy visitor to confidently press the button.&lt;/p&gt;
&lt;h2 id=&quot;the-background-image&quot; tabindex=&quot;-1&quot;&gt;The background image&lt;/h2&gt;
&lt;p&gt;We have a strong message and an action. You might want to consider the wider page next. Many hero headers make use of large background images. These can really bring life to your design and help people connect with the message or feeling behind the design.&lt;/p&gt;
&lt;p&gt;There are lots of great places to buy royalty-free images. A Google search will turn up loads. When I&#39;m getting started on a design I&#39;ll often turn to &lt;a href=&quot;https://unsplash.com/&quot;&gt;Unsplash&lt;/a&gt; as they provide a load of great, free images that I can quickly try in designs and see what sort of images work best.&lt;/p&gt;
&lt;h3 id=&quot;dimensions-and-file-size&quot; tabindex=&quot;-1&quot;&gt;Dimensions and file size&lt;/h3&gt;
&lt;p&gt;When you&#39;ve found your ideal image, you need to prepare it for your hero header. You want the image to be big enough to cover the screen, but not so massive it takes a long time to download. Photos tend to scale up on very large screens quite well so I would usually scale a photo down to about 1400 to 1600px wide. This should look good on most screens.&lt;/p&gt;
&lt;p&gt;Photos should be saved as JPEG files and compressed. Depending on the type of photo you could expect the finished file size to be about 200 to 500KB. Larger sizes will become slow and noticeably delay your site&#39;s loading times. You really want your hero header to appear quickly, so making sure the images you use are compressed is important. I use &lt;a href=&quot;https://tinypng.com/&quot;&gt;Tinypng&lt;/a&gt; as a last step in compressing my images.&lt;/p&gt;
&lt;p&gt;Don&#39;t worry about the name, it&#39;ll work on &lt;code&gt;.jpg&lt;/code&gt; files too!&lt;/p&gt;
&lt;h3 id=&quot;filling-the-entire-viewport&quot; tabindex=&quot;-1&quot;&gt;Filling the entire viewport&lt;/h3&gt;
&lt;p&gt;Screens can be all sorts of sizes. Often we want our hero header to fit itself to the screen but it&#39;s hard to know whether people will have a wide short browser window, or a narrow tall window. We can use two tricks to get our hero header to fill the available space. Setting the background size to &lt;code&gt;cover&lt;/code&gt; and the height of the hero header to &lt;code&gt;100vh&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;.hero-header-container {&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;/images/awesomephotodude.jpg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; no-repeat center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;background-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; cover&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100vh&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; relative&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* Useful for any &quot;absolute&quot; positioned elements inside */&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Setting the background image size to &lt;code&gt;cover&lt;/code&gt; tells the browser to scale and crop the image in such a way that it fills the available space. Keep in mind this means it could crop the sides off on a tall screen, or lose the top and bottom on a wide screen. Experiment to see which works best for you. (Hint: using media queries to show different images at different widths and heights could be an idea here.)&lt;/p&gt;
&lt;p&gt;The &amp;quot;vh&amp;quot; stands for &amp;quot;viewport height&amp;quot; and is a percentage. In this way &lt;code&gt;100vh&lt;/code&gt; means the entire viewport height.&lt;/p&gt;
&lt;h3 id=&quot;adding-a-gradient-on-top&quot; tabindex=&quot;-1&quot;&gt;Adding a gradient on top&lt;/h3&gt;
&lt;p&gt;We have our lovely background image but now we find it&#39;s hard to see our headline! This happens a lot. There are a couple of ways we can fix this. One way might be to blur or darken the original photo. Like in the Tito example above, applying a filter to tone the image back really helps the headline stand out.&lt;/p&gt;
&lt;p&gt;Another approach might be to use the power of CSS. We can make use of CSS to apply a background gradient on top of our hero header&#39;s photo. One way to do this might be to use a pseudo-element:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.hero-header-container:before&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we add a &lt;code&gt;before&lt;/code&gt; pseudo-element that sits behind our content but in front of the background image. In this case it&#39;s a gradient from grey to darker grey. You could substitute a solid colour or a different gradient, or even a background image. Alternately you could add a background colour or image to your heading.&lt;/p&gt;
&lt;p&gt;The main idea is to make sure your foreground text stands out against the photo, like in this example from &lt;a href=&quot;http://bulmers.ie/&quot;&gt;Bulmers.ie&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/bulmers.png&quot; alt=&quot;Bulmers header&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;background-video&quot; tabindex=&quot;-1&quot;&gt;Background video&lt;/h2&gt;
&lt;p&gt;Sometimes having a big image isn&#39;t enough, and you need something more. A popular option is to embed a video in the background of the page and have it play automatically on load. In this example from &lt;a href=&quot;https://storyful.com/&quot;&gt;Storyful&lt;/a&gt; we have a full-screen background image showing the way the company works.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/storyful.png&quot; alt=&quot;Storyful header&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Videos can look great but you need to make sure they&#39;re optimised for the web. This means keeping them short, usually 10 to 20 seconds at most. They should be scaled down to a relatively low resolution and compressed so that the file size is close to 10MB or so.&lt;/p&gt;
&lt;p&gt;Videos can be hosted on your own server but it&#39;s usually better to use a service such as &lt;a href=&quot;http://embed.ly/video&quot;&gt;Embed.ly&lt;/a&gt; to take care of the hassle.&lt;/p&gt;
&lt;p&gt;If you&#39;re looking for great free videos to get started, I&#39;ve found &lt;a href=&quot;https://coverr.co/&quot;&gt;Coverr&lt;/a&gt; a great starting point. It&#39;s like Unsplash but for video.&lt;/p&gt;
&lt;p&gt;You can even mix in a bit of a background image with transparency to act as a mask in front of the video, as seen on this lovely site from &lt;a href=&quot;http://adaptcentre.ie/&quot;&gt;Adapt&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/adapt.png&quot; alt=&quot;Adapt header&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;explainer-video&quot; tabindex=&quot;-1&quot;&gt;Explainer video&lt;/h2&gt;
&lt;p&gt;Setting the scene on your hero header with a background image or video might not be enough. We can still use video though, but put it front and center to tell the story of our brand. In this example from the (now dead, sadly) HomeHero site we see a big video that automatically plays on load.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/homehero.png&quot; alt=&quot;HomeHero header&quot; /&gt;&lt;/p&gt;
&lt;p&gt;We can embed videos like this from Youtube (or Vimeo if you prefer). If using Youtube, the simplest way is to use their &lt;code&gt;iframe&lt;/code&gt; embed option. You can add some custom settings to make it look tidier. Here&#39;s an example:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;iframe&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;560&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;315&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://www.youtube.com/embed/0jhDAVkdsAI?modestbranding=1&amp;amp;cc_load_policy=0&amp;amp;iv_load_policy=3&amp;amp;vq=hd720&amp;amp;rel=0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;frameborder&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;allowfullscreen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;iframe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this I&#39;ve set the &lt;code&gt;modestbranding&lt;/code&gt; to &amp;quot;1&amp;quot;, the &lt;code&gt;vq&lt;/code&gt; to &amp;quot;hd720&amp;quot; and &lt;code&gt;rel&lt;/code&gt; to &amp;quot;0&amp;quot;. Modest branding means the Youtube logo is more subtle, the &lt;code&gt;vq&lt;/code&gt; setting tells it to use a higher quality than the default, and the &lt;code&gt;rel&lt;/code&gt; tells it to not show related videos after the video finishes. There are loads more options in &lt;a href=&quot;https://developers.google.com/youtube/player_parameters&quot;&gt;Youtube&#39;s docs&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;carousels&quot; tabindex=&quot;-1&quot;&gt;Carousels&lt;/h2&gt;
&lt;p&gt;This can sometimes be a tricky one. In the earlier days of the web we had this idea that there was a &amp;quot;fold&amp;quot; (a newspaper term) at the bottom of the screen beyond which all content and hope was lost. This is not necessarily true but the idea persists. Before considering whether a carousel is the right idea, &lt;a href=&quot;https://www.nngroup.com/articles/designing-effective-carousels/&quot;&gt;read up on how to do it right&lt;/a&gt;. You might not need a carousel at all.&lt;/p&gt;
&lt;p&gt;Still, rules are made to be broken. &lt;a href=&quot;http://www.apple.com/&quot;&gt;Apple.com&lt;/a&gt; uses a carousel on their home page. They do so in a way that uses a small number of different screens, which change slowly. Their hero carousel also stops animating once you interact with it and has navigation at the bottom.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/apple.png&quot; alt=&quot;Apple header&quot; /&gt;&lt;/p&gt;
&lt;p&gt;A carousel can be useful for your hero header but be cautious. You don&#39;t want to confuse your visitors with too many messages.&lt;/p&gt;
&lt;h2 id=&quot;branding-and-navigation&quot; tabindex=&quot;-1&quot;&gt;Branding and navigation&lt;/h2&gt;
&lt;p&gt;With an eye catching headline, a clear and intruitive call to action, beautiful images and video, your hero header is looking pretty good. Don&#39;t forget your branding and navigation!&lt;/p&gt;
&lt;p&gt;As we can see in the examples pictured above, it&#39;s common to place your logo in the top left and the menu on the top right. This is a convention and helps visitors know where to look for this information. Sometimes your call to action might be placed alongside the menu. If you do, it can be helpful to highlight it as a button to help it stand out as the most important action.&lt;/p&gt;
&lt;p&gt;Make sure the logo and navigation links are easy to read. If using a large background image you might want to place a bar along the top to help the logo and links stand out.&lt;/p&gt;
&lt;h2 id=&quot;thinking-beyond-the-%22fold%22&quot; tabindex=&quot;-1&quot;&gt;Thinking beyond the &amp;quot;fold&amp;quot;&lt;/h2&gt;
&lt;p&gt;While it can be impressive to take over the screen with your hero header, it&#39;s also ok to let people know there&#39;s more to see below. People are pretty good at scrolling on the web and on mobile it&#39;s even easier than clicking. You can make use of this by having the content that follows your header be visible, encouraging people to scroll.&lt;/p&gt;
&lt;p&gt;Still, studies do show that &lt;a href=&quot;https://www.nngroup.com/articles/page-fold-manifesto/&quot;&gt;the information that people see first is more important than the rest of the page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;What is visible on the page without requiring any action is what encourages us to scroll.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In short, make the most of what&#39;s visible when the page first appears, but also keep in mind that people do scroll. Even if they find that content less important.&lt;/p&gt;
&lt;h2 id=&quot;break-the-rules!&quot; tabindex=&quot;-1&quot;&gt;Break the rules!&lt;/h2&gt;
&lt;p&gt;The approaches laid out here are hopefully useful but don&#39;t be afraid to try your own approach. A nice example is the landing page from BaseCamp. At first glimpse it seems a little chaotic. Their logo is in the middle. Their menu is split up on both sides and they have &lt;strong&gt;three&lt;/strong&gt; headlines.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/hero-header/basecamp.png&quot; alt=&quot;Basecamp header&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Still the header works in my opinion. It clearly shows the problem being solved, it has a highlighted call to action on the top right and the layout encourages people to scroll.&lt;/p&gt;
&lt;h2 id=&quot;animation&quot; tabindex=&quot;-1&quot;&gt;Animation&lt;/h2&gt;
&lt;p&gt;With an awesome hero header in place, something is missing. It&#39;s just loads and appears suddenly. The next step is to add in animation! Next we&#39;ll make your &lt;a href=&quot;https://cssanimation.rocks/animating-hero-header/&quot;&gt;hero header animated&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry><entry>
    <title>🎉 Module 2 is live! 🎉</title>
    <link href="https://cssanimation.rocks/comp-2/"/>
    <updated>2017-04-17T00:00:00Z</updated>
    <id>https://cssanimation.rocks/comp-2/</id>
    <content type="html">&lt;p&gt;You can &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;level up your interaction animations today&lt;/a&gt;. Check out what you get!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Touch and hover animations&lt;/li&gt;
&lt;li&gt;Animating links&lt;/li&gt;
&lt;li&gt;Animating tooltips&lt;/li&gt;
&lt;li&gt;Revealing content on hover&lt;/li&gt;
&lt;li&gt;Animating buttons&lt;/li&gt;
&lt;li&gt;Examples to download&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But wait, there&#39;s more!&lt;/p&gt;
&lt;h2 id=&quot;get-the-course-for-just-%241&quot; tabindex=&quot;-1&quot;&gt;Get the course for just $1&lt;/h2&gt;
&lt;p&gt;This Friday 10 lucky people will be selected to buy this course for just $1.&lt;/p&gt;
&lt;p&gt;There are three ways you can win. Pick one, or you can maximise your chances by doing all three:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure you&#39;re &lt;a href=&quot;https://twitter.com/cssanimation&quot;&gt;following on Twitter&lt;/a&gt; and &lt;a href=&quot;http://twitter.com/intent/tweet?url=http%3A%2F%2Fcourses.cssanimation.rocks%2Fp%2Flevel-up&amp;amp;text=This%20course%20looks%20amazing!%20Level%20up%20your%20CSS%20animation%20skills%20with%20%40CSSAnimation%20https%3A%2F%2Fcssanimation.rocks%2Fimages%2Fcourses%2Flevelup%2Fcover2.png&quot;&gt;give the course a mention&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OR&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.facebook.com/cssanimation&quot;&gt;Like the Facebook page&lt;/a&gt; and &lt;a href=&quot;https://www.facebook.com/dialog/feed?app_id=184683071273&amp;amp;link=http%3A%2F%2Fcourses.cssanimation.rocks%2Fp%2Flevel-up&amp;amp;picture=https%3A%2F%2Fcssanimation.rocks%2Fimages%2Fcourses%2Flevelup%2Fcover2.png&amp;amp;name=New%20CSS%20Animation%20Rocks%20course&amp;amp;caption=%20&amp;amp;description=Learn%20how%20to%20apply%20the%20theory%20of%20CSS%20animations%20in%20this%20video%20course%20from%20CSS%20Animation%20Rocks.&amp;amp;redirect_uri=http%3A%2F%2Fwww.facebook.com%2F&quot;&gt;shout it out on the Facebooks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OR&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure you&#39;ve signed up to the &lt;a href=&quot;https://weekly.cssanimation.rocks/&quot;&gt;CSS Animation Weekly newsletter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Be quick! This competition closes on Friday, 21st April at 12pm GMT.&lt;/p&gt;
&lt;h2 id=&quot;price-going-up-soon&quot; tabindex=&quot;-1&quot;&gt;Price going up soon&lt;/h2&gt;
&lt;p&gt;This Friday the price for the course will go up. You can get the course for just $100 right now, but on Friday it&#39;ll go up to $140. [Sign up now]((http://courses.cssanimation.rocks/p/level-up) and get lifetime access to all current and future content, as well as help and support in our exclusive Slack channel!&lt;/p&gt;
</content>
  </entry><entry>
    <title>Transitions in space</title>
    <link href="https://cssanimation.rocks/space-transitions/"/>
    <updated>2017-04-21T00:00:00Z</updated>
    <id>https://cssanimation.rocks/space-transitions/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;A few simple transitions can make a huge difference. In this article we&#39;ll learn how we can use transitions to bring our content to life, as well as plan and build our hover effects to perform smoothly and look great.&lt;/p&gt;
&lt;h2 id=&quot;transitions-vs-animations&quot; tabindex=&quot;-1&quot;&gt;Transitions vs animations&lt;/h2&gt;
&lt;p&gt;Transitions are a great way to smooth the changes from one state to another (and back again) in the browser. They seem like a simpler alternative to the &lt;code&gt;keyframes&lt;/code&gt; and &lt;code&gt;animation&lt;/code&gt; approach, but they are useful in very different ways.&lt;/p&gt;
&lt;p&gt;For example, a transition isn&#39;t much use if you want an animation to play on load, or if you want it to loop infinitely. But if you have two states and you want to be able to easily animate back and forth between the two, a transition&#39;s the best choice.&lt;/p&gt;
&lt;p&gt;I&#39;ve written more about the differences between &lt;a href=&quot;https://cssanimation.rocks/transition-vs-animation/&quot;&gt;transitions vs animations&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this example we&#39;re going to build up a space scene and introduce a hover effect to reveal some more information about the planet. We&#39;ll see how to think about setting the default and hover states, and what sorts of properties are best used to ensure smooth, jank-free animation.&lt;/p&gt;
&lt;p&gt;You can find the &lt;a href=&quot;https://codepen.io/donovanh/full/qmNgXW/&quot;&gt;full demo here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-states&quot; tabindex=&quot;-1&quot;&gt;Setting the states&lt;/h2&gt;
&lt;p&gt;When creating transitions most of the time and effort needs to go into the before and after states. We need to think about how it&#39;s going to look before the transition and then how it needs to look once the transition has finished.&lt;/p&gt;
&lt;p&gt;When I&#39;m building more complex transitions I tend to not worry too much about the movement between these states until I&#39;m happy that both states look right. Having said that it&#39;s important to think about the properties we use to create the &lt;code&gt;hover&lt;/code&gt; state, as these properties are going to be animated.&lt;/p&gt;
&lt;p&gt;Before we get into that though let&#39;s set up the starting and hover states.&lt;/p&gt;
&lt;h3 id=&quot;starting-state&quot; tabindex=&quot;-1&quot;&gt;Starting state&lt;/h3&gt;
&lt;p&gt;We begin with out planets places in the middle of the screen. The moon happily rotates around the earth.&lt;/p&gt;
&lt;p&gt;The HTML contains an article within which we have our &lt;code&gt;earth&lt;/code&gt; and &lt;code&gt;moon&lt;/code&gt; elements. I&#39;ve also wrapped the &lt;code&gt;moon&lt;/code&gt; in a &lt;code&gt;moon-container&lt;/code&gt; div as this will help when repositioning it later for the hover effect.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;article&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;earth-demo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;earth&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cssanimation.rocks/images/random/earth.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;moon-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;moon&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cssanimation.rocks/images/random/moon.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;article&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&#39;s the CSS we use. For the &lt;code&gt;earth&lt;/code&gt; element we position it absolutely, and use a &lt;code&gt;calc&lt;/code&gt; trick to position it in the middle both horizontally and vertically.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 100px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The image is also positioned and given a height and width.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the moon we do something similar. Beginning by placing the container in the middle of the screen.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.moon-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 25px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;50% - 25px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We set up the dimensions for the moon and give it an animation using the &lt;code&gt;spin&lt;/code&gt; keyframes. This will set it spinning around the Earth.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.moon&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; spin 20s linear infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;pointer-events&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 25px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At this point through, the moon is actually positioned in the middle of the screen, right on top of the earth. Let&#39;s use a &lt;code&gt;transform&lt;/code&gt; to push the moon outside it&#39;s container and outside the planet.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.moon img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-160px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-160px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This means that when the &lt;code&gt;moon&lt;/code&gt; div rotates on top of the planet Earth, the actual image will be rotating further out. Next we give the images a border radius to tidy up any antialiasing issues and a &lt;code&gt;box-shadow&lt;/code&gt; to give them a blue glow.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth img, .moon img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0 12em 1em &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;110&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 140&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 200&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; .6&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lastly, we want the &lt;code&gt;moon&lt;/code&gt; to spin, so we create some keyframes. This is a simple one, we just want the animation to rotate around the Z-axis by 360 degrees.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; spin&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;360deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&#39;s what we have so far.&lt;/p&gt;
&lt;p data-height=&quot;500&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;aWZPeP&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Planet hover effect part 1: initial stage&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/donovanh/pen/aWZPeP/&quot;&gt;Planet hover effect part 1: initial stage&lt;/a&gt; by Donovan Hutchinson (&lt;a href=&quot;http://codepen.io/donovanh&quot;&gt;@donovanh&lt;/a&gt;) on &lt;a href=&quot;http://codepen.io/&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;showing-more-info&quot; tabindex=&quot;-1&quot;&gt;Showing more info&lt;/h3&gt;
&lt;p&gt;We&#39;d like to show some useful information about the planet Earth on hover. Perhaps useful for alien visitors to get some insight into our home before they visit.&lt;/p&gt;
&lt;p&gt;Before we set up the hover state we need to add this extra info.&lt;/p&gt;
&lt;p&gt;We begin by expanding the HTML to add in a &lt;code&gt;more-info&lt;/code&gt; block containing some text.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;article&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;earth-demo&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;earth&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;more-info&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Earth&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Third planet from the Sun&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Atmosphere: 21% oxygen&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Liquid water on surface&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Only planet that has life (that we know of)&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cssanimation.rocks/images/random/earth.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;moon-container&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;moon&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cssanimation.rocks/images/random/moon.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;article&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is added within the &lt;code&gt;earth&lt;/code&gt; container as I&#39;d like it to be part of the hover effect, so that when the cursor hovers the text it&#39;ll stay on the screen.&lt;/p&gt;
&lt;p&gt;In our CSS we add some styles for this &lt;code&gt;more-info&lt;/code&gt; block.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth .more-info&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;linear-gradient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to bottom&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;10&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;10&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;10&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #fff&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 400px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth .more-info h1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 0 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; right&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&#39;re setting the background colour and border radius, text colour as well as padding and width. We&#39;re also scaling it a little using the scale &lt;code&gt;transform&lt;/code&gt; and we set the &lt;code&gt;transform-origin&lt;/code&gt; to the top-left corner so that it will scale from that direction.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;opacity&lt;/code&gt; for this &lt;code&gt;more-info&lt;/code&gt; block is set to zero so that it&#39;s invisible. We could go further and add in &lt;code&gt;visibility&lt;/code&gt; to make sure the content doesn&#39;t interfere with other content but for this demo it&#39;s fine.&lt;/p&gt;
&lt;h3 id=&quot;transitioning-the-right-properties&quot; tabindex=&quot;-1&quot;&gt;Transitioning the right properties&lt;/h3&gt;
&lt;p&gt;When setting up the hover transition animation it&#39;s important to think about performance. Properties such as height, padding, font-size or background-position can all be animated but they don&#39;t tend to perform well. The reason being that they cause the browser to recalculate all sorts of other details in the layout when they change.&lt;/p&gt;
&lt;p&gt;It&#39;s a good idea to stick to the &lt;code&gt;opacity&lt;/code&gt; and &lt;code&gt;transform&lt;/code&gt; properties when animating as these do tend to perform well and don&#39;t cause any &amp;quot;jankiness&amp;quot;.&lt;/p&gt;
&lt;p&gt;In this example we&#39;re using the transform and opacity properties. The &lt;code&gt;more-info&lt;/code&gt; block is scaled down a little with a transform and has opacity of 0. In our hover state we can&lt;/p&gt;
&lt;p&gt;How we make use of the transform and opacity properties specifically. Let&#39;s set up the hover state to set the &lt;code&gt;more-info&lt;/code&gt; block to be visible, while getting the planet itself out of the way.&lt;/p&gt;
&lt;h2 id=&quot;hover-effect&quot; tabindex=&quot;-1&quot;&gt;Hover effect&lt;/h2&gt;
&lt;p&gt;Let&#39;s start setting up each of the &lt;code&gt;.earth:hover&lt;/code&gt; states. If you&#39;re using Sass you can write this a little more succinctly but for now I&#39;m using vanilla CSS.&lt;/p&gt;
&lt;p&gt;Firstly let&#39;s more the planet out of the way.&lt;/p&gt;
&lt;p&gt;.earth:hover img {&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-75px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-75px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;This &lt;code&gt;transform&lt;/code&gt; pushes the planet up and left by 75 pixels while scaling it down to 50% in size. Powerful!&lt;/p&gt;
&lt;p&gt;Next we do a similar thing to the moon.&lt;/p&gt;
&lt;p&gt;.earth:hover ~ .moon-container {&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-75px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-75px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.5&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;.earth:hover ~ .moon-container img {&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;transform: translateX(-140px) translateY(-140px);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;There&#39;s a second tweak here to the moon&#39;s image. I&#39;m adjusting its &lt;code&gt;transform&lt;/code&gt; to bring it a little closer to the earth. Next we show the &lt;code&gt;more-info&lt;/code&gt; block.&lt;/p&gt;
&lt;p&gt;.earth:hover .more-info {&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;opacity: 1;
transform: none;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;This sets the opacity to 1, making it visible and we set the &lt;code&gt;transform&lt;/code&gt; to &lt;code&gt;none&lt;/code&gt; so that the block scales up to the normal size.&lt;/p&gt;
&lt;p&gt;Here&#39;s the result. Hover over the planet to see the content.&lt;/p&gt;
&lt;p data-height=&quot;500&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;bWezpR&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Planet hover effect part 2: basic hover effect&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/donovanh/pen/bWezpR/&quot;&gt;Planet hover effect part 2: basic hover effect&lt;/a&gt; by Donovan Hutchinson (&lt;a href=&quot;http://codepen.io/donovanh&quot;&gt;@donovanh&lt;/a&gt;) on &lt;a href=&quot;http://codepen.io/&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;applying-transitions&quot; tabindex=&quot;-1&quot;&gt;Applying transitions&lt;/h2&gt;
&lt;p&gt;Now that the hard work is done, all we need to do now is tell the browser &lt;strong&gt;how&lt;/strong&gt; to transform between these states. Thankfully there&#39;s not too much involved. Most of the transitions can be handled with one CSS rule.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo *&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; all 4s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1.5&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.3&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&#39;s break this down. Firstly this rule uses the asterisk &amp;quot;*&amp;quot; to make it apply to all elements within the &lt;code&gt;earth-demo&lt;/code&gt; article.&lt;/p&gt;
&lt;p&gt;It then applies a &lt;code&gt;transition&lt;/code&gt; to &lt;em&gt;all&lt;/em&gt; properties, lasting &lt;em&gt;4 seconds&lt;/em&gt; and using a cubic-bezier timing function. This function is a kind of exponential ease-out, meaning that it starts off very fast and slows down toward the end. It also overshoots a little and settles back.&lt;/p&gt;
&lt;p&gt;Before we call it a day, let&#39;s just add a little nuance to the list of text. It would be nice to call attention to the list elements by having them animate into place one at a time. Thankfully we can do that with the &lt;code&gt;transition-delay&lt;/code&gt; property.&lt;/p&gt;
&lt;h3 id=&quot;transition-delays&quot; tabindex=&quot;-1&quot;&gt;Transition delays&lt;/h3&gt;
&lt;p&gt;We first want to set the opacity for these items to zero so that they are invisible before the transition starts.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo h1, li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then when the &lt;code&gt;hover&lt;/code&gt; happens, we show them.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo:hover h1, li&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next we want to delay each of the 4 list items. We can do that using the &lt;code&gt;nth-child&lt;/code&gt; selector.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo:hover li:nth-child(1)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo:hover li:nth-child(2)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.2s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo:hover li:nth-child(3)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.4s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.earth-demo:hover li:nth-child(4)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0.6s&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will add a delay to each of the list items. Since we&#39;re using the &amp;quot;*&amp;quot; selector above, each of these list items has a transition and we only need to specify a delay.&lt;/p&gt;
&lt;p&gt;Here&#39;s the finished result.&lt;/p&gt;
&lt;p data-height=&quot;500&quot; data-theme-id=&quot;12592&quot; data-slug-hash=&quot;qmNgXW&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Planet hover effect part 3: with transition&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/donovanh/pen/qmNgXW/&quot;&gt;Planet hover effect part 3: with transition&lt;/a&gt; by Donovan Hutchinson (&lt;a href=&quot;http://codepen.io/donovanh&quot;&gt;@donovanh&lt;/a&gt;) on &lt;a href=&quot;http://codepen.io/&quot;&gt;CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So there we have it! A seemingly complicated animation, I mean &lt;em&gt;transition&lt;/em&gt; carried out with just one CSS rule.&lt;/p&gt;
&lt;p&gt;In this article we&#39;ve learned how to approach planning and building the states for an impressive transition, and made sure our animation is smooth and looks great.&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot; tabindex=&quot;-1&quot;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;There&#39;s loads we can do to bring our websites to life using animation and this is just one small part. If you&#39;d like to become an expert in applying movement to your UI and web projects, don&#39;t miss your chance to &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;Level up your CSS animation skills&lt;/a&gt; today!&lt;/p&gt;
</content>
  </entry><entry>
    <title>🎉 Module 3 is live! 🎉</title>
    <link href="https://cssanimation.rocks/module-3/"/>
    <updated>2017-05-21T00:00:00Z</updated>
    <id>https://cssanimation.rocks/module-3/</id>
    <content type="html">&lt;p&gt;​Hello there! This is a quick update to let you know that I&#39;ve added another 44 minutes of videos to the course &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up&quot;&gt;Level up your CSS animation skills&lt;/a&gt;. Module 3 is officially live! You can check it out right now.&lt;/p&gt;
&lt;p&gt;This is a great module. We&#39;ll be putting on our JavaScript hats and creating a function that attaches a class to visible elements on the screen. We can use this to animate, show or hide elements as visitors scroll our pages. Along the way we&#39;ll animate an article about making pizza, and even fly to the moon. (If you spot the theme, tweet &lt;a href=&quot;https://twitter.com/cssanimation&quot;&gt;@cssanimation&lt;/a&gt; to let me know!)&lt;/p&gt;
&lt;h2 id=&quot;what&#39;s-that%3F-examples-you-say!%3F&quot; tabindex=&quot;-1&quot;&gt;What&#39;s that? Examples you say!?&lt;/h2&gt;
&lt;p&gt;Sure - check out what we&#39;re building in this module. Firstly we&#39;re &lt;a href=&quot;https://cssanimation.rocks/levelup/public/03/02-end/&quot;&gt;animating elements on scroll on this article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We&#39;re also bringing parallax to this &lt;a href=&quot;https://cssanimation.rocks/levelup/public/03/02-end/&quot;&gt;flight to the moon&lt;/a&gt;. 🚀&lt;/p&gt;
&lt;p&gt;Topics include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scroll animations... (1m 50s)&lt;/li&gt;
&lt;li&gt;Animating content on scroll (14m 52s)&lt;/li&gt;
&lt;li&gt;Animating a slide-in banner (6m 17s)&lt;/li&gt;
&lt;li&gt;Parallax scrolling (10m 57s)&lt;/li&gt;
&lt;li&gt;Mouse-leave animation (10m 40s)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&#39;m working on a final part containing examples to download and use on your projects. Stay tuned for another update when the examples are done!​&lt;/p&gt;
&lt;p&gt;Enjoy! I hope you find this module helpful. It was a load of fun to create!&lt;/p&gt;
&lt;h2 id=&quot;while-you&#39;re-here...&quot; tabindex=&quot;-1&quot;&gt;While you&#39;re here...&lt;/h2&gt;
&lt;p&gt;I wanted to ask. Do you know anyone who might enjoy learning about CSS animation? If so, please let them know about the course! If you like, you can give them a 20% discount with the code &amp;quot;friend&amp;quot;. We&#39;re all friends here after all!&lt;/p&gt;
&lt;p&gt;Here&#39;s a link &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up?code=friend&quot;&gt;with the 20% discount included&lt;/a&gt;! Spread the word.&lt;/p&gt;
&lt;p&gt;Have a lovely week!&lt;/p&gt;
</content>
  </entry><entry>
    <title>Happy birthday to the newsletter 🎁</title>
    <link href="https://cssanimation.rocks/one-year/"/>
    <updated>2017-07-23T00:00:00Z</updated>
    <id>https://cssanimation.rocks/one-year/</id>
    <content type="html">&lt;p&gt;I can&#39;t believe it&#39;s been a year since I launched &lt;a href=&quot;http://weekly.cssanimation.rocks/&quot;&gt;CSS Animation Weekly&lt;/a&gt;, a regular digest of hand-picked CSS animation inspiration and tutorials. In that time we&#39;ve seen almost 500 examples of amazing animation work, tutorials and articles.&lt;/p&gt;
&lt;p&gt;To celebrate issue #52 of the email, I&#39;m giving away 10 places on my &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up?code=friend&quot;&gt;new CSS animation course&lt;/a&gt; with a massive &lt;em&gt;$140&lt;/em&gt; each. Want to win a place? It&#39;s easy!&lt;/p&gt;
&lt;p&gt;To win yourself a place on this course, all you need to do is retweet &lt;a href=&quot;https://twitter.com/cssanimation/status/889219091898277888&quot;&gt;this tweet&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; data-partner=&quot;tweetdeck&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Stickers! 🎁 Enrol now and get a free limited-edition CSS Animation sticker - AND save 20% 🙌 &lt;a href=&quot;https://t.co/PvVarod59o&quot;&gt;https://t.co/PvVarod59o&lt;/a&gt; &lt;a href=&quot;https://t.co/6tZK0370dJ&quot;&gt;pic.twitter.com/6tZK0370dJ&lt;/a&gt;&lt;/p&gt;&amp;mdash; CSS Animation (@cssanimation) &lt;a href=&quot;https://twitter.com/cssanimation/status/889219091898277888&quot;&gt;July 23, 2017&lt;/a&gt;&lt;/blockquote&gt;
&lt;p&gt;You can just press that retweet button there ^&lt;/p&gt;
&lt;p&gt;10 lucky winners will be picked this Friday, July 28th! Best of luck! ☘️&lt;/p&gt;
&lt;p&gt;By the way, if you can&#39;t wait till then, you can take advantage of a massive &lt;a href=&quot;http://courses.cssanimation.rocks/p/level-up?code=friend&quot;&gt;20% discount&lt;/a&gt; today.&lt;/p&gt;
&lt;p&gt;Thank you to everyone who has subscribed and supported &lt;a href=&quot;http://weekly.cssanimation.rocks/&quot;&gt;CSS Animation Weekly&lt;/a&gt;. 💌&lt;/p&gt;
</content>
  </entry><entry>
    <title>Create an animated scroll cue</title>
    <link href="https://cssanimation.rocks/scroll-cue/"/>
    <updated>2019-04-28T00:00:00Z</updated>
    <id>https://cssanimation.rocks/scroll-cue/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;In this tutorial we&#39;re going to add a subtle cue to the bottom of the page that lets people know that they can scroll to see more content. We&#39;ll use animation to make it easier to notice and even creating a nice &amp;quot;heartbeat&amp;quot; animation along the way.&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
  &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube-nocookie.com/embed/1JRqQTRLSQc&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;In our previous lessons&lt;/a&gt; we&#39;ve animated the background, and used staggered animations to introduce the titles. The page is beginning to look pretty animated, but it leaves just one last piece, the scroll cue.&lt;/p&gt;
&lt;p&gt;Whether we need an arrow to tell people to scroll is a topic for debate. Some would suggest that it&#39;s no better than a sticky plaster, and that a better idea would be to design the layout of the page in such a way that scrolling is more obvious. Let&#39;s leave the discussion aside for the moment, and instead we&#39;ll use this as an opportunity to see how multiple CSS animations can be combined in one little detail.&lt;/p&gt;
&lt;p&gt;To code along with this lesson, grab the &lt;a href=&quot;https://cssanimation.rocks/levelup/public/01/01.zip&quot;&gt;sample code zip file&lt;/a&gt; and look for folder &lt;code&gt;02-introduce-titles&lt;/code&gt;.  A completed version of this lesson&#39;s code is in the folder &lt;code&gt;03-scroll-cue&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;callout&quot;&gt;
```html
&lt;p&gt;This post is part of my &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;amazing 4-hour video course on CSS animation&lt;/a&gt;. I&#39;m currently offering a massive 93% discount for CSS animation fans. &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;Reserve your place today!&lt;/a&gt;&lt;/p&gt;
```
&lt;/div&gt;
&lt;h2 id=&quot;adding-the-html-and-css&quot; tabindex=&quot;-1&quot;&gt;Adding the HTML and CSS&lt;/h2&gt;
&lt;p&gt;To get started, we add some extra HTML to our page. I&#39;ve include a chevron image in the &lt;code&gt;images&lt;/code&gt; folder. Add the following HTML to the &lt;code&gt;header&lt;/code&gt; section of the HTML, outside the &lt;code&gt;header-content&lt;/code&gt; section.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;header-down-arrow&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;images/downarrow.png&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;50&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;ll use this to position the image. Next, in our CSS, set up styles for the chevron&#39;s container.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-down-arrow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4vh&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;re positioning this absolutely and using &lt;code&gt;text-align: center&lt;/code&gt; to place the image inside it in the horizontal center of the screen. It&#39;s positioned 4% of the screen&#39;s height away from the bottom, so should be visible on all screens, whether they be desktop or mobile. I&#39;ve also made sure to set the &lt;code&gt;z-index&lt;/code&gt; here to a value higher than 1 as the header content also covers the entire screen and we want to make sure this chevron is on top and visible.&lt;/p&gt;
&lt;p&gt;Looking at the result we see a nicely positioned down arrow at the bottom of the screen.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;Ppbvbd&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with scroll cue / chevron (no animation)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/Ppbvbd/&quot;&gt;Landing page with scroll cue / chevron (no animation)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;animation-1%3A-introduce-the-chevron&quot; tabindex=&quot;-1&quot;&gt;Animation 1: Introduce the chevron&lt;/h2&gt;
&lt;p&gt;We begin with the &lt;code&gt;keyframes&lt;/code&gt;. Since we&#39;re trying to convey the idea that people can scroll the page, we can hint at that with the animation on this scroll cue. If the chevron slides up as it appears, it will suggest that direction of movement. We&#39;ll create some keyframes called &amp;quot;fade-slide-up&amp;quot;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; fade-slide-up&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4rem&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This animation is very similar to the &lt;code&gt;fade-slide-down&lt;/code&gt; animation we made in lesson 1. The only difference is the starting &lt;code&gt;transform&lt;/code&gt;, where we&#39;re setting it to start 4rem down instead of up.&lt;/p&gt;
&lt;p&gt;If this rings alarm bells, don&#39;t worry, we&#39;re going to do some optimising in the next lesson and see if we can trim some of this back a bit. For now though we&#39;ll create new keyframes for this animation.&lt;/p&gt;
&lt;p&gt;We then apply this to our chevron image.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-down-arrow img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; fade-slide-up 1s 1s ease-out forwards&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have the animation name, a duration of 1 second, a delay of 1 second and a basic &lt;code&gt;ease-out&lt;/code&gt; timing function. We also set the opacity to 0 so that there&#39;s no flash at the start before the animation begins.&lt;/p&gt;
&lt;p&gt;Here is in in action.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;xqRNrq&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with scroll cue / chevron (slide up animation)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/xqRNrq/&quot;&gt;Landing page with scroll cue / chevron (slide up animation)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you look carefully you might notice that the chevron animates into place last. It finishes just after the last of the content has stopped moving. The idea is that visitors will subconsciously notice this and be more likely to notice that there&#39;s a scroll cue. This is a subtle detail and perhaps easily missed, so we can go further and add a second animation to this chevron. Let&#39;s make it pulse.&lt;/p&gt;
&lt;h2 id=&quot;heartbeat&quot; tabindex=&quot;-1&quot;&gt;Heartbeat&lt;/h2&gt;
&lt;p&gt;So far all the &lt;code&gt;keyframes&lt;/code&gt; we&#39;ve built have only had start (0%) and end (100%) states. Let&#39;s build an animation with 3 states.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; pulse&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;50%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .8&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this we&#39;ve added in a middle state, 50%. The animation begins with the chevron at full size, then scales it down at the halfway point, before scaling back up again. It also fades a little when it&#39;s &amp;quot;further away&amp;quot; from the viewer. This should be useful to create a subtle beating effect.&lt;/p&gt;
&lt;p&gt;We apply this to our image by adding a second animation to the &lt;code&gt;animation&lt;/code&gt; property.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-down-arrow img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; fade-slide-up 1s 1s ease-out forwards&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
             pulse 2s 3s ease-out infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Multiple animations, like multiple backgrounds, are added by using commas. Each will stack and should work in parallel. You should be careful through when more than one of the &lt;code&gt;keyframes&lt;/code&gt; operates on the same property, such as &lt;code&gt;transform&lt;/code&gt;, it can cause problems. I&#39;m using a delay here of 3 seconds for the &amp;quot;pulse&amp;quot; animation to make sure it doesn&#39;t start while the &amp;quot;fade-slide-up&amp;quot; is animating.&lt;/p&gt;
&lt;p&gt;In this case the &amp;quot;pulse&amp;quot; animation has a duration of 2 seconds, a delay of 3 seconds, the old &lt;code&gt;ease-out&lt;/code&gt; timing and lastly an &lt;code&gt;animation-iteration-count&lt;/code&gt; of &lt;em&gt;infinite&lt;/em&gt;. Since we&#39;re telling this animation to play forever, we don&#39;t need to specify the fill-mode.&lt;/p&gt;
&lt;p&gt;We can see it in action here.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;XMNwaj&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with scroll cue / chevron (slide up and pulse animation)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/XMNwaj/&quot;&gt;Landing page with scroll cue / chevron (slide up and pulse animation)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;a-note-about-safari&quot; tabindex=&quot;-1&quot;&gt;A note about Safari&lt;/h2&gt;
&lt;p&gt;While the above works well in most browsers, it runs into trouble with Safari. Hopefully this is something that will be fixed in future but for now we can fix it by splitting these two animations up and applying one of them to the container.&lt;/p&gt;
&lt;p&gt;First we remove the &amp;quot;pulse&amp;quot; animation from the &lt;code&gt;.header-down-arrow img&lt;/code&gt; block and move it to the &lt;code&gt;.header-down-arrow&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.header-down-arrow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pulse 2s 3s ease-out infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4vh&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;z-index&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The animation will wait 3 seconds before starting, and there&#39;s no longer any conflict with the &amp;quot;fade-slide-up&amp;quot; keyframes. Phew!&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;mWOYBj&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with scroll cue / chevron (slide up and pulse animation - fix for Safari)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/mWOYBj/&quot;&gt;Landing page with scroll cue / chevron (slide up and pulse animation - fix for Safari)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;subtle-is-best&quot; tabindex=&quot;-1&quot;&gt;Subtle is best&lt;/h2&gt;
&lt;p&gt;It&#39;s easy to go crazy and make all the things animate, but that&#39;s rarely a good thing for your visitors. People want to be able to read and use the site without being bombarded with movement, so do go easy on the infinite animations. In this case it&#39;s quite a subtle animation. Experiment with what works for you, but do dial it back to the point where the animation &lt;em&gt;helps&lt;/em&gt; your visitors rather than gets in the way.&lt;/p&gt;
&lt;h2 id=&quot;want-to-learn-more%3F&quot; tabindex=&quot;-1&quot;&gt;Want to learn more?&lt;/h2&gt;
&lt;p&gt;This was part of my &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;amazing 4-hour video course on CSS animation&lt;/a&gt;. As a fan of this site you can save a massive 93% on the course today.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;Save 93% and Level Up Your CSS Animation Skills&lt;/a&gt; today!&lt;/p&gt;
</content>
  </entry><entry>
    <title>Animating Links</title>
    <link href="https://cssanimation.rocks/animating-links/"/>
    <updated>2019-05-05T00:00:00Z</updated>
    <id>https://cssanimation.rocks/animating-links/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;The humble text link, or anchor, is a mainstay of the World Wide Web. For a long time links were always blue and underlined, until CSS came along and gave us the tools to change the colour and style and even animate our link hover effects.&lt;/p&gt;
&lt;p&gt;In this tutorial we will learn how we style and animate the underlines on our links, we will combine multiple transitions, group animation keyframes together, and investigate some of the upsides and downsides of using animations instead of transitions.&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
  &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube-nocookie.com/embed/CP4VzMN5EW0&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;You&#39;ll need some files to follow this tutorial. Download &lt;a href=&quot;https://cssanimation.rocks/levelup/public/02/02.zip&quot;&gt;this zip file&lt;/a&gt;, and open folder &lt;code&gt;00-start&lt;/code&gt; in the &lt;code&gt;02&lt;/code&gt; folder. A completed version of this lesson&#39;s code is in the folder &lt;code&gt;01-anchors&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You&#39;ll notice there are loads more examples there too - you&#39;ll find &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;all the lessons on this course&lt;/a&gt; if you&#39;d like to learn more.&lt;/p&gt;
&lt;h2 id=&quot;starting-html-and-css&quot; tabindex=&quot;-1&quot;&gt;Starting HTML and CSS&lt;/h2&gt;
&lt;p&gt;To begin we have some simple HTML. Inside the containing &lt;code&gt;content&lt;/code&gt; article you&#39;ll find a paragraph of text with a link. Nothing too fancy here.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;article&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;... and here is some text. This text shows how &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;https://cssanimation.rocks/&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;CSS animation&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; can help us make links be more fun and useful...&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;article&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&#39;re going to style this link using CSS, so let&#39;s open the stylesheet &lt;code&gt;links.css&lt;/code&gt;. It&#39;s empty for now.&lt;/p&gt;
&lt;p&gt;Testing in the browser we see a simple paragraph with a &amp;quot;normal&amp;quot; looking link, complete with the default blue colour and text underline.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;xqmJzN&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/xqmJzN/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;replacing-the-underline&quot; tabindex=&quot;-1&quot;&gt;Replacing the underline&lt;/h2&gt;
&lt;p&gt;Let&#39;s start by replacing, and then animating the underline on the text. Many sites choose to remove the underline from links and rely on colour or font-weight to help links stand out. This is fine, but worth keeping in mind that some visitors might be colour-blind or have trouble making out subtle differences, so do test carefully.&lt;/p&gt;
&lt;h2 id=&quot;accessibility&quot; tabindex=&quot;-1&quot;&gt;Accessibility&lt;/h2&gt;
&lt;p&gt;Just to note. While I&#39;m using &amp;quot;:hover&amp;quot; in these examples, do keep in mind that you can also make use of the &amp;quot;:focus&amp;quot; state here too for keyboard navigation. For the purposes of these examples I am trying to keep things as simple as possible, but it&#39;s important to keep in mind other ways that people will be accessing our sites and applications.&lt;/p&gt;
&lt;p&gt;Also, we&#39;re setting link colours here. So you&#39;ll want to think about what style you want to apply to &amp;quot;visited&amp;quot; links. It can be useful to know which links on a page your visitors have visited before!&lt;/p&gt;
&lt;p&gt;OK back to the CSS. In our &lt;code&gt;links.css&lt;/code&gt; stylesheet file, set the anchor styling to &lt;code&gt;text-decoration: none&lt;/code&gt;, and the same on &lt;code&gt;hover&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a {
  text-decoration: none;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-decoration&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the underline gone, we can now put it back! Only this time we&#39;ll create our own that we can animate.&lt;/p&gt;
&lt;p&gt;One possible approach could be to add a &lt;code&gt;border-bottom&lt;/code&gt; to the links. We&#39;ll see how it looks.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a {
  border-bottom: .1em solid blue;
  text-decoration: none;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the browser we can see the result. It&#39;s not great, the border sits very low, far away from the text.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;KWbBxR&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/KWbBxR/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let&#39;s try another approach, using a pseudo-element.&lt;/p&gt;
&lt;h2 id=&quot;pseudo-elements-%3A-vs-%3A%3A&quot; tabindex=&quot;-1&quot;&gt;Pseudo-elements : vs ::&lt;/h2&gt;
&lt;p&gt;Back when Internet Explorer 8 was a popular browser, we used to write pseudo-elements using a single colon &amp;quot;:&amp;quot; like &amp;quot;:after&amp;quot;. However the standard nowadays is to use two colons like so &amp;quot;::&amp;quot;. You may have noticed in the last module I used the older approach. This should be fine for now but for future compatibility it&#39;s a better idea to use two. A big thank you to one of my students for pointing this out! I&#39;ll be using two colons in the pseudo-elements from now on.&lt;/p&gt;
&lt;p&gt;Back to our CSS.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a {
  position: relative;
  text-decoration: none;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .1em solid #2F56B0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .14em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we add an &lt;code&gt;after&lt;/code&gt; pseudo-element, using &amp;quot;::after&amp;quot;. We set a border on the top first. Then we give it the empty &amp;quot;content&amp;quot; property it needs, and position it absolutely. To make this work we need to also go back and set the &lt;code&gt;position&lt;/code&gt; to &amp;quot;relative&amp;quot; on the anchor element. This tells the browser to use the anchor as a container for the absolutely positioned element within it.&lt;/p&gt;
&lt;p&gt;We&#39;re setting the &lt;code&gt;right&lt;/code&gt; and the &lt;code&gt;left&lt;/code&gt; to &amp;quot;0&amp;quot; so that the line goes all the way across the link. Lastly the &amp;quot;bottom&amp;quot; is set to be slightly higher than the bottom of the container, in this case &amp;quot;.14em&amp;quot; from the bottom. In the browser we can see that this now positions nicely.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;qrLyJW&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/qrLyJW/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;styling-the-underline&quot; tabindex=&quot;-1&quot;&gt;Styling the underline&lt;/h2&gt;
&lt;p&gt;Since we&#39;ve created our own pseudo-underline we can apply styles. Like &lt;code&gt;border-radius&lt;/code&gt; for example. We could add in a border radius and create an oval shaped underline using &lt;code&gt;border-radius: 50%&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 50%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .1em solid #2F56B0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .14em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We could even change the border style to &lt;code&gt;dotted&lt;/code&gt; or &lt;code&gt;dashed&lt;/code&gt; for some crazy styles, or even apply an SVG or image as the underline. Do experiment and see what works for you.&lt;/p&gt;
&lt;p&gt;For this example though we&#39;ll keep it simple so that we can focus on the animation. I&#39;ll just add a small border radius to make the border better match the style of this rounded font.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .1em solid #2F56B0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .14em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Time to add some animation.&lt;/p&gt;
&lt;h2 id=&quot;animating-the-underline-(transitions)&quot; tabindex=&quot;-1&quot;&gt;Animating the underline (transitions)&lt;/h2&gt;
&lt;p&gt;To see what sorts of things we can do with this we&#39;ll try both a &lt;code&gt;transition&lt;/code&gt; and an &lt;code&gt;animation&lt;/code&gt; to see how each works. First we&#39;ll try a &lt;code&gt;transition&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can adjust the style of the &lt;code&gt;after&lt;/code&gt; pseudo-element on hover. To do so add a new block called &lt;code&gt;a:hover::after&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This contains the hover style for the pseudo-element. Let&#39;s adjust the positioning so that the line goes from left to right on hover. First we change the &lt;code&gt;right&lt;/code&gt; property on the pseudo-element to &amp;quot;100%&amp;quot;. Then add a hover position where the line goes all the way across, by setting &lt;code&gt;right&lt;/code&gt; to 0.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .1em solid #2F56B0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .14em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Testing this in the browser, it doesn&#39;t look like much yet.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;ZeVjqq&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/ZeVjqq/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We&#39;ll need to add a transition to see this change from left to right.&lt;/p&gt;
&lt;p&gt;In the pseudo-element, add a transition that will transition the &amp;quot;right&amp;quot; property over a duration of .4s and using the cubic-bezier timing function with coordinates &amp;quot;0,.5,0,1&amp;quot;. This timing function starts very fast and tapers off, like an exponential ease-out.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .1em solid #2F56B0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .14em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; right .4s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.5&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We now see the underline animate from left to right on hover.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;QpzBzm&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/QpzBzm/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It&#39;s worth noting that we&#39;re animating the &lt;code&gt;right&lt;/code&gt; property here. This is potentially a source of problems as it&#39;s not as optimised as if we&#39;d animated the &lt;code&gt;transform&lt;/code&gt; or &lt;code&gt;opacity&lt;/code&gt;, but in this case it&#39;ll be ok as this transition doesn&#39;t move the element or cause any page reflowing.&lt;/p&gt;
&lt;p&gt;Before we finish up with the transition effect on the underline, let&#39;s add in some colour animation.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a {
  color: #2F56B0;
  position: relative;
  text-decoration: none;
  transition: color .4s ease-out;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Back in the original anchor style block, we set the colour to match the border. We also want this colour to animate on hover, so we add a &lt;code&gt;transition&lt;/code&gt; property to act only on the &amp;quot;color&amp;quot; property, with a duration of .4s and a simple &amp;quot;ease-out&amp;quot; timing function.&lt;/p&gt;
&lt;p&gt;Next we need to add another colour for the hover states of both the anchor and the pseudo-element.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #457DFB&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-decoration&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #457DFB&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The anchor has the new colour set, and then the same colour is applied to the &lt;code&gt;border-color&lt;/code&gt; on the pseudo-element. Lastly we need to add another &lt;code&gt;transition&lt;/code&gt; to the pseudo-element to make this colour animation work.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .1em solid #2F56B0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .14em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; right .4s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.5&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
              border-color .4s ease-out&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the transition we add a comma, then a second transition specific to the &lt;code&gt;border-color&lt;/code&gt; property. This will match the timing and duration of the anchor&#39;s &lt;code&gt;color&lt;/code&gt; transition.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;xqmJNK&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/xqmJNK/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;how-we-use-transitions&quot; tabindex=&quot;-1&quot;&gt;How we use transitions&lt;/h3&gt;
&lt;p&gt;In this example we&#39;ve seen how transitions smooth the state change between an element&#39;s default state and its hover state. We&#39;ve also seen how the transitions can be applied to multiple properties.&lt;/p&gt;
&lt;p&gt;The way we went about building the transition is worth looking at. We built each state, and then at the end added a transition to create the animation between the states. This is very different to how we design animations using &lt;code&gt;keyframes&lt;/code&gt;. Rather than build the animation entirely within the keyframes, we plan out each state in advance and the &lt;code&gt;transition&lt;/code&gt; property does the job of smoothing the changes between states.&lt;/p&gt;
&lt;p&gt;We can specify transitions properties when we set up the transitions - so for example the colour property changes using a different timing function to the other properties. We can use this to create more nuanced animations.&lt;/p&gt;
&lt;p&gt;Before we finish up though let&#39;s see how we can use an &lt;code&gt;animation&lt;/code&gt; with &lt;code&gt;keyframes&lt;/code&gt; to add animation to the hover event.&lt;/p&gt;
&lt;h2 id=&quot;animating-the-underline-(keyframes)&quot; tabindex=&quot;-1&quot;&gt;Animating the underline (keyframes)&lt;/h2&gt;
&lt;p&gt;Where the &lt;code&gt;transition&lt;/code&gt; property smoothes the changes between two states, we can use animations to introduce more than two states, to play automatically on load, and to repeat. These are features transitions don&#39;t give us, so it might be useful to make use of animations on hover states in some cases.&lt;/p&gt;
&lt;p&gt;For this example we&#39;ll set up the animation to repeat infinitely as long as the mouse is hovering over the link.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@keyframes&lt;/span&gt; anchor-underline&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;0%, 10%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;40%, 60%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;90%, 100%&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We set up the &lt;code&gt;keyframes&lt;/code&gt; with the name &amp;quot;anchor-underline&amp;quot;. In this we have three sets of pairs of keyframes. First 0% and 10%, then 40% and 60%, and lastly 90% and 100%. This is a little different from the way we&#39;ve written keyframes so far, so it&#39;s worth explaining. When we want keyframes to have the same properties, we can list them together separated by commas. What this says is that the 0% and 10% states will be the same as each other, as well as the 40 and 60, and the 90 and 100.&lt;/p&gt;
&lt;p&gt;In effect this means that the animation doesn&#39;t change between 0% and 10%. However it then will animate between 10% and 40%, at which point it will remain unchanged until 60%, and so on.&lt;/p&gt;
&lt;p&gt;We add styles initially for the &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;right&lt;/code&gt; positions. At first these styles make the line invisible, but pressed up against the left side. In the middle we set the left and right to 0, meaning the line is stretched across the entire link. Lastly we push the left up to 100% to squash the line against the right side.&lt;/p&gt;
&lt;p&gt;We then change our &lt;code&gt;:hover::after&lt;/code&gt; block, removing the &lt;code&gt;right&lt;/code&gt; property and replacing it with the &lt;code&gt;animation&lt;/code&gt; property.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;a:hover::after&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; anchor-underline 2s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.5&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; infinite&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #457DFB&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We specify the animation name, a duration of 2 seconds, the same timing function as earlier and lastly we give it an iteration count of &amp;quot;infinite&amp;quot;. This means it will run forever, as long as the link is hovered over. Let&#39;s see this in action.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;EWGpzB&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;Landing page with animated foreground elements (not staggered)&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/EWGpzB/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For as long as we hold the hover state, the animation plays.&lt;/p&gt;
&lt;h2 id=&quot;transition-vs-animation&quot; tabindex=&quot;-1&quot;&gt;Transition vs animation&lt;/h2&gt;
&lt;p&gt;This is one advantage the &lt;code&gt;animation&lt;/code&gt; property has over &lt;code&gt;transition&lt;/code&gt;. We can have animations that repeat, or alternate, or go through multiple stages. Transitions are more limited in this sense in that they only afford us the animation between one state and another. Having said that, there&#39;s a significant advantage to the transition approach, in that the hover effect gets a second, &amp;quot;out&amp;quot; transition for free. By applying the transition property to the anchor styles, the browser transitions both to and from the hover state, even if the mouse leaves halfway through the animation.&lt;/p&gt;
&lt;p&gt;As we can see, this gives us a smoother mouse out effect.&lt;/p&gt;
&lt;p&gt;When choosing whether to use animation or transition for interactions it good to keep in mind this benefit. For the rest of this module we&#39;ll be focusing on how we can make the most of the transitions to provide smooth animated responses to interactions.&lt;/p&gt;
&lt;h2 id=&quot;multiple-lines&quot; tabindex=&quot;-1&quot;&gt;Multiple lines&lt;/h2&gt;
&lt;p&gt;The above works well for links in a single line, but it can break when we make the text wrap multiple lines.&lt;/p&gt;
&lt;p&gt;This &lt;a href=&quot;https://www.dannyguo.com/blog/animated-multiline-link-underlines-with-css/&quot;&gt;blog post&lt;/a&gt; sets out a good approach - using &lt;code&gt;background-image&lt;/code&gt; instead of the border on the link element. So if you&#39;re looking at animating links on multiple lines, you can set it up like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a {
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-position: 0% 100%;
  background-repeat: no-repeat;
  background-size: 0% 4px;
  transition: background-size cubic-bezier(0,.5,0,1) 0.3s;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;a:hover,
a:focus {
  text-decoration: none;
  background-size: 100% 4px;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here it is in action:&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;mYeJdP&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; class=&quot;codepen&quot;&gt;See the Pen &lt;a href=&quot;http://codepen.io/donovanh/pen/mYeJdP/&quot;&gt;See the example on CodePen&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-we-learned&quot; tabindex=&quot;-1&quot;&gt;What we learned&lt;/h2&gt;
&lt;p&gt;In this lesson we learned how to create custom underline effects on our links, we combined multiple transitions and also applied them to different properties. We then looked at how the animation property differs in how it could be used for hover animations and created keyframe animations with grouped keyframes.&lt;/p&gt;
&lt;h2 id=&quot;want-to-learn-more%3F&quot; tabindex=&quot;-1&quot;&gt;Want to learn more?&lt;/h2&gt;
&lt;p&gt;This was part of my &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;video course on CSS animation&lt;/a&gt;. As a fan of this site you can save a massive 93% on the course today.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;Save over 90% and Level Up Your CSS Animation Skills&lt;/a&gt; today!&lt;/p&gt;
</content>
  </entry><entry>
    <title>UI Animation in React</title>
    <link href="https://cssanimation.rocks/ui-animation-react/"/>
    <updated>2019-05-12T00:00:00Z</updated>
    <id>https://cssanimation.rocks/ui-animation-react/</id>
    <content type="html">&lt;p&gt;On this site we&#39;ve explored loads of big impressive animations. I thought it would be worth stepping back and looking at how small UI animations can add up.&lt;/p&gt;
&lt;p&gt;In this post we&#39;ll take a look at a demo React app and explore how adding animations to situations when UI changes can result in a more polished experience. We&#39;ll try to do so in a way that means reusing animations so that the result is a more consistent style of animation through the app, and we&#39;ll take a look at a handy little React package we can use to make animations easier.&lt;/p&gt;
&lt;h2 id=&quot;video-version&quot; tabindex=&quot;-1&quot;&gt;Video version&lt;/h2&gt;
&lt;p&gt;Note: the code is hard to see in the video, but you&#39;ll find all these examples and code below!&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube-nocookie.com/embed/6lshX4daC_c&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 id=&quot;demo-project&quot; tabindex=&quot;-1&quot;&gt;Demo project&lt;/h2&gt;
&lt;p&gt;Over on Github I&#39;ve prepared a little React project to get started. If you&#39;ve ever used &lt;code&gt;Create React App&lt;/code&gt;, it&#39;ll be quite familiar. It&#39;s a basic React app with components, around which I&#39;ve added &lt;a href=&quot;https://www.styled-components.com/&quot;&gt;styled-components&lt;/a&gt; to handle styling.&lt;/p&gt;
&lt;p&gt;Styled Components is a handy way of wrapping CSS styling around components in React, allowing us to use Sass-style nesting but also provides us with a way of injecting a &amp;quot;theme&amp;quot; - a set of objects containing settings or snippets of CSS we can apply throughout our apps. We&#39;ll use this theme approach to create some simple but useful animations we can apply to projects.&lt;/p&gt;
&lt;p&gt;You can &lt;a href=&quot;https://github.com/donovanh/react-animation-example&quot;&gt;clone the repo&lt;/a&gt; and run &lt;code&gt;npm install&lt;/code&gt; to set up the necessary bits. Then run &lt;code&gt;npm start&lt;/code&gt; to run it locally. You&#39;ll find it on &lt;a href=&quot;http://localhost:3000/&quot;&gt;&lt;code&gt;localhost:3000&lt;/code&gt;&lt;/a&gt; in the browser.&lt;/p&gt;
&lt;p&gt;If you&#39;d like to see the finished version, check out branch &lt;code&gt;animated&lt;/code&gt; - otherwise you can follow along.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cssanimation.rocks/images/posts/ui-animation-react/code.png&quot; alt=&quot;Demo app and code&quot; /&gt;&lt;/p&gt;
&lt;p&gt;What we have is a simple Create React App, into which I&#39;ve added some &lt;a href=&quot;https://www.styled-components.com/&quot;&gt;styled components&lt;/a&gt; goodness. You don&#39;t have to stick with Styled Components if you prefer Emotion or something else - got for it. It&#39;s just to illustrate the approach.&lt;/p&gt;
&lt;p&gt;What we&#39;re starting with is a fairly simple little 3 page website with some &amp;quot;products&amp;quot; for sale on it. You can click between the products, you can select product variations, which results in their prices changing. You can even add them to the cart and see the cart button and cart total update.&lt;/p&gt;
&lt;p&gt;In the project you&#39;ll find a &lt;code&gt;components&lt;/code&gt; directory. This is where I&#39;ve set up the components for the app. The include a product page, and smaller things like navigation, images and buttons.&lt;/p&gt;
&lt;p&gt;You&#39;ll also find a &lt;code&gt;theme&lt;/code&gt; folder. This is where I&#39;ve set up some global CSS rules, along with some theme values that are injected into the components thanks to styled components. We&#39;ll look at how this can help make our animations reusable.&lt;/p&gt;
&lt;h2 id=&quot;opportunities-to-animate&quot; tabindex=&quot;-1&quot;&gt;Opportunities to animate&lt;/h2&gt;
&lt;p&gt;When something changes, it&#39;s an opportunity to use animation. In this example we have lots of places where the UI changes.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/J4lwPWbcA71TKvHOBH&quot; width=&quot;480&quot; height=&quot;330&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Let&#39;s begin with the biggest change - moving between pages.&lt;/p&gt;
&lt;h3 id=&quot;page-transitions&quot; tabindex=&quot;-1&quot;&gt;Page transitions&lt;/h3&gt;
&lt;p&gt;I&#39;m a big fan of keeping things simple. I also love it when I can write something once and use it in many places. Let&#39;s do both to make the page transitions better.&lt;/p&gt;
&lt;p&gt;Here&#39;s how they currently look. No animation, just sudden changes:&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/l0QxLxuzgqiodZdb3i&quot; width=&quot;480&quot; height=&quot;330&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;In the &lt;code&gt;theme&lt;/code&gt; folder we&#39;ll open the &lt;code&gt;index.js&lt;/code&gt; file. We already have a bunch of settings here I&#39;ve thrown in to demonstrate how a theme might look, but it doesn&#39;t have any animations yet. Let&#39;s change that. Begin by adding an object with a set of CSS keyframes I&#39;ll call &lt;code&gt;show&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Add to the top of &lt;code&gt;theme/index.js&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;In theme/index add a set of keyframes:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; keyframes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;@keyframes show {
    to {
      opacity: 1;
      transform: none;
    }
  }&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a flexible little animation as it will simply apply an &lt;code&gt;opacity&lt;/code&gt; of 1 and &lt;code&gt;transform&lt;/code&gt; &amp;quot;none&amp;quot; to whatever we decide to apply it to.&lt;/p&gt;
&lt;p&gt;As we&#39;re only using the &lt;code&gt;to&lt;/code&gt; state in the animation, the starting state will be implied from the styles we give to our component.&lt;/p&gt;
&lt;p&gt;This will be useful when we want to fade in the page content as we can set the page content to an &lt;code&gt;opacity&lt;/code&gt; of 0, then apply the &lt;code&gt;show&lt;/code&gt; animation.&lt;/p&gt;
&lt;p&gt;With the keyframes in place then we set up an animation:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; animations &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;
    animation: show 500ms ease-out forwards;
    &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;keyframes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;show&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&#39;re creating an &lt;code&gt;animations&lt;/code&gt; variable with another object, this time containing the same property name, &lt;code&gt;show&lt;/code&gt; but the property contains the CSS code that applies the animation, and bundles the keyframes along with it.&lt;/p&gt;
&lt;p&gt;Before we can use this we have to add it to the exports at the bottom of the file.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; theme &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    animations&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;etc&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can now apply our themed animation &lt;code&gt;show&lt;/code&gt; to the pages. In &lt;code&gt;components/ProductPage/index.js&lt;/code&gt; scroll down to the styling on line &lt;code&gt;44&lt;/code&gt; and add:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props =&gt; props.theme.animations.show&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As this is only applying the &amp;quot;to&amp;quot; or finished state of our animation, it won&#39;t do much. We need give the page a starting state.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;animation-delay: 200ms;
opacity: 0;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the page begins with an &lt;code&gt;opacity&lt;/code&gt; of 0. We also apply an &lt;code&gt;animation-delay&lt;/code&gt; to hold back the animation for 200 milliseconds - enough to make it a little more noticeable.&lt;/p&gt;
&lt;p&gt;Testing this in the browser we have a simple but pleasant fade effect. Let&#39;s reuse the &lt;code&gt;show&lt;/code&gt; animation once more.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/m94f44PD3QvRZYiNJt&quot; width=&quot;480&quot; height=&quot;330&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;This time in the &lt;code&gt;.content&lt;/code&gt; part of the styles, add the following:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.content&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props =&gt; props.theme.animations.show&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;animation-delay&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 500ms&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;20px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 40px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We are reusing the &lt;code&gt;show&lt;/code&gt; animation but this time waiting a little longer with a longer delay. Notice also the &lt;code&gt;transform&lt;/code&gt;. This will be reset by the &lt;code&gt;show&lt;/code&gt; animation, resulting in an animated slide up the screen as it fades in.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/Q5u2TIl7ImAXFvsrxH&quot; width=&quot;480&quot; height=&quot;330&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Feel free to experiment with other ways this could be used - maybe different timings on headings, paragraph content to create a staggered animation.&lt;/p&gt;
&lt;h2 id=&quot;other-ui-animations&quot; tabindex=&quot;-1&quot;&gt;Other UI animations&lt;/h2&gt;
&lt;p&gt;There are still loads of places where things change in this UI. Let&#39;s bring in a handy library called &lt;a href=&quot;http://github.com/nearform/react-animation/&quot;&gt;React Animation&lt;/a&gt; and see how we can use it&#39;s helper components to make our changes animate.&lt;/p&gt;
&lt;h3 id=&quot;react-animation&quot; tabindex=&quot;-1&quot;&gt;React Animation&lt;/h3&gt;
&lt;p&gt;As you can see on &lt;a href=&quot;https://nearform.github.io/react-animation/&quot;&gt;the React Animation demo page&lt;/a&gt;, you get two helpful components to apply animation to UI elements. Let&#39;s apply each.&lt;/p&gt;
&lt;p&gt;To begin, we install React Animation with &lt;code&gt;npm install -S react-animation&lt;/code&gt;. We can now use it in our components!&lt;/p&gt;
&lt;h3 id=&quot;animating-the-price&quot; tabindex=&quot;-1&quot;&gt;Animating the price&lt;/h3&gt;
&lt;p&gt;Let&#39;s use the defaults and add a fade animation to the price when it changes. In &lt;code&gt;components/ProductPage/index.js&lt;/code&gt; we begin by importing the &lt;code&gt;AnimateOnChange&lt;/code&gt; component (at the top of the file):&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; AnimateOnChange &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; from &lt;span class=&quot;token string&quot;&gt;&#39;react-animation&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we wrap the &amp;quot;price&amp;quot; text with this component:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;AnimateOnChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{currentPrice}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;AnimateOnChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By default, the &lt;code&gt;AnimateOnChange&lt;/code&gt; component will look for any change in the children components and apply a fade-out and fade-in when they change.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/dBNIuB3rfZWg70b6iC&quot; width=&quot;480&quot; height=&quot;148&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;We can configure this with some options.&lt;/p&gt;
&lt;h3 id=&quot;add-to-cart-button&quot; tabindex=&quot;-1&quot;&gt;Add to cart button&lt;/h3&gt;
&lt;p&gt;When adding an item to the cart, the text changes. Let&#39;s have this animate but with some more bounciness this time.&lt;/p&gt;
&lt;p&gt;Around line 33 of &lt;code&gt;components/ProductPage/index.js&lt;/code&gt; where we wrap the button&#39;s contents:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;AnimateOnChange&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;animationIn&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bounceIn&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;animationOut&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;bounceOut&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  {addingToCart ? &#39;Added to cart&#39; : &#39;Add to Cart&#39;}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;AnimateOnChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&#39;re specifying &lt;code&gt;animationIn&lt;/code&gt; and &lt;code&gt;animationOut&lt;/code&gt;. You&#39;ll find more examples of built-in animations in the &amp;quot;Animations&amp;quot; section of &lt;a href=&quot;https://nearform.github.io/react-animation/&quot;&gt;the React Animation demo page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Checking in the browser, we now have a bounce animation on click.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/kdiYLxGGXjNExm18iy&quot; width=&quot;480&quot; height=&quot;365&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;h3 id=&quot;cart-total&quot; tabindex=&quot;-1&quot;&gt;Cart total&lt;/h3&gt;
&lt;p&gt;Let&#39;s add some animation to the badge on the cart icon on the top-right. Currently it&#39;ll change each time we press &amp;quot;Add to cart&amp;quot; but there&#39;s no animation.&lt;/p&gt;
&lt;p&gt;To make it really stand out, we might want to have it animate last. This would draw the eye toward the cart button - something we might want people to notice when shopping.&lt;/p&gt;
&lt;p&gt;To do this we can use the &lt;code&gt;durationOut&lt;/code&gt; prop.&lt;/p&gt;
&lt;p&gt;In the &lt;code&gt;components/CartButton/index.js&lt;/code&gt; file on line 13, replace the &lt;code&gt;span&lt;/code&gt; with this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;AnimateOnChange
  className=&amp;quot;cart-button-total&amp;quot;
  animationIn=&amp;quot;bounceIn&amp;quot;
  animationOut=&amp;quot;bounceOut&amp;quot;
  durationOut={2000}
&amp;gt;
  {total}
&amp;lt;/AnimateOnChange&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that we&#39;re passing in the &lt;code&gt;className&lt;/code&gt;. This applies the styling I&#39;ve already set up for &lt;code&gt;cart-button-total&lt;/code&gt; but it&#39;ll also apply the &lt;code&gt;AnimateOnChange&lt;/code&gt; animation. In this case we&#39;re passing in &lt;code&gt;2000&lt;/code&gt; (milliseconds) as the &lt;code&gt;durationOut&lt;/code&gt;. This means it should disappear slowly, and animate back in later.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/cKzkvr0HN6KcKcGHC6&quot; width=&quot;480&quot; height=&quot;403&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;h3 id=&quot;hideuntilloaded&quot; tabindex=&quot;-1&quot;&gt;HideUntilLoaded&lt;/h3&gt;
&lt;p&gt;Now that we have the interactions animated, let&#39;s look at one more situation. When we change pages, the product images take a moment to load. Since they have a background shadow and background colour, this leaves big empty boxes visible for a moment before the image appears.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/VeBWcZnzBqOizNKykx&quot; width=&quot;480&quot; height=&quot;330&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;Let&#39;s fix this using &lt;code&gt;HideUntilLoaded&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In the file &lt;code&gt;components/ImageAndVariations/index.js&lt;/code&gt; we begin by importing the component:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; HideUntilLoaded &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; from &lt;span class=&quot;token string&quot;&gt;&#39;react-animation&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then around line 41 we look for the &lt;code&gt;img&lt;/code&gt; tag, which we&#39;ll wrap in the &lt;code&gt;HideUntilLoaded&lt;/code&gt; component:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;HideUntilLoaded&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;imageToLoad&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;{image}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;{image}&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;{title}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;HideUntilLoaded&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now when we change views, any new images will hold back on loading until ready.&lt;/p&gt;
&lt;iframe src=&quot;https://giphy.com/embed/jnE8jIDzbBtBVARosp&quot; width=&quot;480&quot; height=&quot;330&quot; frameBorder=&quot;0&quot; class=&quot;giphy-embed&quot; allowFullScreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;You can find more options for &lt;code&gt;HideUntilLoaded&lt;/code&gt; such as passing in a &amp;quot;Loading&amp;quot; component, using other animations and more on &lt;a href=&quot;https://nearform.github.io/react-animation/&quot;&gt;the React Animation demo page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Be sure to check out the other ways the components can be used to bring animations to your UI!&lt;/p&gt;
&lt;h2 id=&quot;level-up-your-css-animation-skills!&quot; tabindex=&quot;-1&quot;&gt;Level up your CSS animation skills!&lt;/h2&gt;
&lt;p&gt;If you like this, you&#39;ll love my &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;video course on CSS animation&lt;/a&gt;. As a fan of this site you can save over 90% on the course today.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;Save over 90% and Level Up Your CSS Animation Skills&lt;/a&gt; today!&lt;/p&gt;
</content>
  </entry><entry>
    <title>Scroll animations</title>
    <link href="https://cssanimation.rocks/scroll-animations/"/>
    <updated>2019-05-19T00:00:00Z</updated>
    <id>https://cssanimation.rocks/scroll-animations/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;It&#39;s time to add some animation to our page when a visitor scrolls. For this tutorial I&#39;ve set up a demo page all about pizza. We&#39;ll use this to learn how to have animations triggered by scrolling, and investigate ways we can do so efficiently.&lt;/p&gt;
&lt;p&gt;In this tutorial we&#39;ll learn how to make use of the &lt;code&gt;requestAnimationFrame&lt;/code&gt; as well as &lt;code&gt;Intersection Observer&lt;/code&gt; methods to detect when elements are within the viewport of the browser. We&#39;ll introduce a new &lt;code&gt;will-change&lt;/code&gt; property and use that to make sure our animations are smooth, and we&#39;ll put these together with some transitions to create animations that are triggered on scroll.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: The video doesn&#39;t include the &lt;code&gt;Intersection Observer&lt;/code&gt; approach but you&#39;ll find it in the code below.&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
  &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/-ths7kNIFnw&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;p&gt;You&#39;ll find the HTML and CSS you need to get started in &lt;a href=&quot;https://cssanimation.rocks/levelup/public/03/03.zip&quot;&gt;this sample code file&lt;/a&gt;. Look for folder &lt;code&gt;01-start&lt;/code&gt;. A completed version of this tutorial&#39;s code is in the folder &lt;code&gt;01-end&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;starting-html&quot; tabindex=&quot;-1&quot;&gt;Starting HTML&lt;/h2&gt;
&lt;p&gt;In the &lt;code&gt;index.html&lt;/code&gt; file you&#39;ll find a couple of page sections. The first is a &lt;code&gt;header&lt;/code&gt; that contains the main photo and heading text.&lt;/p&gt;
&lt;p&gt;Beneath this we have a longer article. It&#39;s made up of paragraphs and images. I&#39;ve added the class &lt;code&gt;inline-photo&lt;/code&gt; to each of these images. We&#39;ll use this class to style the images, as well as animate them.&lt;/p&gt;
&lt;p&gt;Let&#39;s see how it looks. We can see the images and the text, but no animation yet.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-zoom=&quot;05&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;BRdaGj&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 id=&quot;showing-on-scroll&quot; tabindex=&quot;-1&quot;&gt;Showing on scroll&lt;/h2&gt;
&lt;p&gt;For this tutorial we&#39;ll be using some JavaScript. The idea is to check, as the page is scrolled, for any special elements we want to animate. If any of these special elements are visible, we can give them a special class and use CSS to animate or transition them into view.&lt;/p&gt;
&lt;p&gt;To do this we&#39;ll need two things. We&#39;ll need the JavaScript to detect and add a class when one of these elements is visible, and we&#39;ll need to set up before and after styles on the elements.&lt;/p&gt;
&lt;h2 id=&quot;javascript&quot; tabindex=&quot;-1&quot;&gt;JavaScript&lt;/h2&gt;
&lt;p&gt;Let&#39;s begin with our JavaScript. At the end of the HTML file you&#39;ll find a reference to the JavaScript file &lt;code&gt;show-on-scroll.js&lt;/code&gt;. This is in the &lt;code&gt;javascripts&lt;/code&gt; folder.&lt;/p&gt;
&lt;p&gt;In our editor we&#39;ll open this file. It&#39;s blank for now. This is where we&#39;ll set up the code to detect scrolling and check for those elements we want to show.&lt;/p&gt;
&lt;p&gt;We won&#39;t be using jQuery for this one. Instead we&#39;re going to use a handy method built in to browsers called &lt;code&gt;requestAnimationFrame&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Back in the day when building something like this I&#39;d have used the &lt;code&gt;scroll&lt;/code&gt; browser event, and then checked the state of the page while scrolling.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;scroll&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Scrollin&#39;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This might work in some ways, but sadly this has a couple of big problems. The first being efficiency. When scrolling, the &lt;code&gt;console.log&lt;/code&gt; here will fire like crazy. If we&#39;re doing anything like parsing the DOM tree or other heavy tasks, this will add a lot of overhead to the browser. It could very easily slow things down and make our animations janky.&lt;/p&gt;
&lt;p&gt;A second issue is iOS. Scrolling on some phones only results in this &lt;code&gt;scroll&lt;/code&gt; trigger being fired after the scrolling has finished. We&#39;d like this to work on mobile, so that&#39;s a big fail there.&lt;/p&gt;
&lt;p&gt;Thankfully &lt;code&gt;requestAnimationFrame&lt;/code&gt; solves these issues. It&#39;s a method that we can use to repeatedly check our page to see if elements are visible, while making sure we don&#39;t overload the browser by checking thousands of times per second. It does this by limiting how often the callback is executed to either the screen&#39;s refresh rate or 60 times per second.&lt;/p&gt;
&lt;p&gt;60 times per second might sound like a lot but for the work we&#39;ll be doing it&#39;s very slow and won&#39;t overload the browser.&lt;/p&gt;
&lt;p&gt;To set up our &lt;code&gt;requestAnimationFrame&lt;/code&gt; method we&#39;ll apply it to a variable. This way we are able to have a fallback function for browsers that don&#39;t yet support it.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; scroll &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;requestAnimationFrame &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;callback&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we&#39;re saying that &lt;code&gt;scroll&lt;/code&gt; should be the &lt;code&gt;window.requestAnimationFrame&lt;/code&gt; method, or (if this isn&#39;t available), use this simple function that waits one-sixtieth of a second before calling the callback.&lt;/p&gt;
&lt;p&gt;Next we&#39;ll grab the elements on the page we want to look out for.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; elementsToShow &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;.show-on-scroll&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will look for all elements with class &lt;code&gt;show-on-scroll&lt;/code&gt; and return them as an array we can loop through.&lt;/p&gt;
&lt;p&gt;Let&#39;s set up that looping function.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;  elementsToShow&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isElementInViewport&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      element&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;classList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;is-visible&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      element&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;classList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;is-visible&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;  scroll(loop);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We begin by setting up the function &lt;code&gt;loop&lt;/code&gt;. This is a function we want to loop through all the elements and check if they&#39;re visible. We do this using the &lt;code&gt;forEach&lt;/code&gt; method. For each of the &lt;code&gt;show-on-scroll&lt;/code&gt; elements found this loop will check if it&#39;s in the viewport, and if so, add the class &lt;code&gt;is-visible&lt;/code&gt;. Otherwise it&#39;ll remove the class.&lt;/p&gt;
&lt;p&gt;Lastly we want to keep firing this function so we&#39;ll make use of our &lt;code&gt;requestAnimationFrame&lt;/code&gt; helper we set up earlier, and pass this function as a callback.&lt;/p&gt;
&lt;p&gt;This means that as soon as &lt;code&gt;requestAnimationFrame&lt;/code&gt; allows us, it&#39;ll repeat this function and update classes as needed.&lt;/p&gt;
&lt;p&gt;As it stands, this won&#39;t do much yet. We need to kick it off by calling the &lt;code&gt;loop&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;loop();
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;checking-if-in-the-viewport&quot; tabindex=&quot;-1&quot;&gt;Checking if in the viewport&lt;/h3&gt;
&lt;p&gt;There&#39;s one bit missing. In the &lt;code&gt;loop&lt;/code&gt; function we&#39;re calling a method &lt;code&gt;isElementInViewport&lt;/code&gt;. Unfortunately this isn&#39;t a browser method, we&#39;ll have to write that one ourselves. Here&#39;s a handy one I grabbed from Stack Overflow.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Helper function from: http://stackoverflow.com/a/7557433/274826&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;isElementInViewport&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;el&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// special bonus for those using jQuery&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt; jQuery &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;function&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; el &lt;span class=&quot;token keyword&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;jQuery&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    el &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; el&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rect &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; el&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getBoundingClientRect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;top &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bottom &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bottom &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;innerHeight &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;documentElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;clientHeight&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
      rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;top &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;innerHeight &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;documentElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;clientHeight&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;top &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
      rect&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bottom &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;innerHeight &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;documentElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;clientHeight&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just to run through this quickly. It begins by checking to see if &lt;code&gt;jQuery&lt;/code&gt; is defined. jQuery changes the way elements are made available and this corrects for a possible issue that might arise. Next it uses a handy method called &lt;code&gt;getBoundingClientRect&lt;/code&gt;. This is the rectangle around the element we want to check.&lt;/p&gt;
&lt;p&gt;Next it does a series of checks that will return true if the element is on the page and on the screen.&lt;/p&gt;
&lt;h3 id=&quot;alternate-approach%3A-intersection-observer&quot; tabindex=&quot;-1&quot;&gt;Alternate approach: Intersection Observer&lt;/h3&gt;
&lt;p&gt;The above works pretty well, but there&#39;s a newer way to approach this problem using the browser&#39;s &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API&quot;&gt;Intersection Observer API&lt;/a&gt;. This is quite well supported in browsers, with the exception of Internet Explorer (currently IE11 does not support this, so will need a polyfill).&lt;/p&gt;
&lt;p&gt;The Intersection Observer looks at the target element&#39;s position in relation to a &lt;code&gt;root&lt;/code&gt; element, and when they &amp;quot;intersect&amp;quot;, will return true. In this case we can use it to tell us when our &lt;code&gt;show-on-scroll&lt;/code&gt; elements are within the viewport.&lt;/p&gt;
&lt;p&gt;When setting up an instance of &lt;code&gt;IntersectionObserver&lt;/code&gt; we can pass in options such as the &lt;code&gt;root&lt;/code&gt; element want, or even the &amp;quot;margin&amp;quot; by which the elements need to overlap. For now though I&#39;ll keep it simpler and just use the defaults. See the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API&quot;&gt;docs&lt;/a&gt; for more details.&lt;/p&gt;
&lt;p&gt;We can replace the above JavaScript with this:&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;callback&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;entries&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    entry&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;classList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toggle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;is-visible&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; observer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;IntersectionObserver&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;callback&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; targets &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;.show-on-scroll&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
targets&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  observer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To step through this - it&#39;s first setting up a &lt;code&gt;callback&lt;/code&gt; function that will be called every time one of our observed targets enters or leaves the viewport.&lt;/p&gt;
&lt;p&gt;We then instantiate the &lt;code&gt;observer&lt;/code&gt; using this callback function. With those two pieces put together, we then grab all our &lt;code&gt;targets&lt;/code&gt;, and loop through them, attaching a listener (&lt;code&gt;observe&lt;/code&gt;) to each one. When the element enters or leaves the viewport, it&#39;ll run the &lt;code&gt;callback&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;Lastly, this &lt;code&gt;callback&lt;/code&gt; function toggles the class &lt;code&gt;is-visible&lt;/code&gt; on our element. This approach is simpler that the previous JavaScript but do keep in mind that it might not work so well in Internet Explorer currently. Check the &lt;a href=&quot;https://caniuse.com/#feat=intersectionobserver&quot;&gt;CanIUse page&lt;/a&gt; for more info.&lt;/p&gt;
&lt;p&gt;Let&#39;s save this and set up our HTML to make use of this new power.&lt;/p&gt;
&lt;h2 id=&quot;selecting-the-elements&quot; tabindex=&quot;-1&quot;&gt;Selecting the elements&lt;/h2&gt;
&lt;p&gt;While there&#39;s a bit going on there in the JavaScript, the result is quite simple. It&#39;s going to apply an &lt;code&gt;is-visible&lt;/code&gt; class when selected elements show on the screen. Let&#39;s choose which elements we want to show.&lt;/p&gt;
&lt;p&gt;In our &lt;code&gt;index.html&lt;/code&gt; file we start by adding the class &lt;code&gt;show-on-scroll&lt;/code&gt; to each of the photos.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;images/pizza.jpg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;inline-photo show-on-scroll&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lastly we&#39;ll also add this class to the &lt;code&gt;header&lt;/code&gt; of the page. It&#39;ll be nice to have an animation on the titles and since this is just adding a class, we can totally do that in CSS.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;header&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;header show-on-scroll&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In our browser we can now test this. Opening the inspector we should see the &lt;code&gt;is-visible&lt;/code&gt; class appearing and disappearing as we scroll.&lt;/p&gt;
&lt;p&gt;Time to use this for some animation!&lt;/p&gt;
&lt;h2 id=&quot;animating-the-photos&quot; tabindex=&quot;-1&quot;&gt;Animating the photos&lt;/h2&gt;
&lt;p&gt;In the &lt;code&gt;scroll.css&lt;/code&gt; file in the &lt;code&gt;stylesheets&lt;/code&gt; folder we find some initial styles for the photos. Let&#39;s set these up to be animated by making a few changes.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.inline-photo&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em solid #fff&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4em solid #fff&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; .25em&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1em 1em 2em .25em &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2em auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translateY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;4em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-5deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transform 4s .25s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.3&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
              opacity .3s .25s ease-out&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;max-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 600px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 90%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;will-change&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transform&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; opacity&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We want these to fade in so we set the &lt;code&gt;opacity&lt;/code&gt; to zero. Then we also want these photos to slide into place, so let&#39;s adjust the transform to &lt;code&gt;translate&lt;/code&gt; them down 4em, and give them a few degrees more rotation.&lt;/p&gt;
&lt;p&gt;Next we set up the transition we want to happen when these photos become visible. We add a transition for the transform, with a duration of 4 seconds, a quarter-second delay and the exponential ease-out timing function. We also fade it in using the opacity property, making it a little quicker than the transform.&lt;/p&gt;
&lt;p&gt;We&#39;re using a delay so that if our visitor is scrolling slowly, the animation won&#39;t have finished before the photo is properly visible on screen. It&#39;s a small tweak helps the flow of the page.&lt;/p&gt;
&lt;p&gt;Lastly we add a property we&#39;ve not used yet, the &lt;code&gt;will-change&lt;/code&gt; property. This is a way of telling the browser to prepare to animate the element. We supply this property the values &lt;code&gt;transform&lt;/code&gt; and &lt;code&gt;opacity&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;With this done, the photos will be invisible. We need to add some CSS to make them visible.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.inline-photo.is-visible&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rotateZ&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-2deg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We add a new rule for the &lt;code&gt;is-visible&lt;/code&gt; classed elements. In this we make them visible with &lt;code&gt;opacity&lt;/code&gt; of 1, and we set the &lt;code&gt;transform&lt;/code&gt; to just a slight rotation.&lt;/p&gt;
&lt;p&gt;Here&#39;s how it looks, showing the images as we scroll down the page.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;aWyPpP&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 id=&quot;animating-the-header&quot; tabindex=&quot;-1&quot;&gt;Animating the header&lt;/h2&gt;
&lt;p&gt;So far so good! Let&#39;s make use of the same JavaScript to bring animation to the header.&lt;/p&gt;
&lt;p&gt;Earlier we added the &lt;code&gt;show-on-scroll&lt;/code&gt; class to the header. We can make use of the &lt;code&gt;is-visible&lt;/code&gt; class to animate this part too. We&#39;ll need to set up a couple of different animations. First we&#39;ll have it fade in, then the main photo will pop into place and the text will slide up into place beneath it.&lt;/p&gt;
&lt;p&gt;Since we&#39;re doing this by applying a class, we have a situation where there&#39;s a change from one state to another. When we change from one state to another it&#39;s a good opportunity to use transitions, but if we wanted to do something more advanced here we could also use &lt;code&gt;keyframes&lt;/code&gt; and animations.&lt;/p&gt;
&lt;p&gt;For now though we&#39;ll get by with a couple of transitions. Whenever possible I like to try to use the simplest approach before jumping into more complex solutions.&lt;/p&gt;
&lt;p&gt;We begin by fading in the &lt;code&gt;header&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;header {
  opacity: 0;
  transition: opacity .5s .25s ease-out;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;header.is-visible&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We create a &lt;code&gt;header&lt;/code&gt; style block and set the &lt;code&gt;opacity&lt;/code&gt; to 0, as well as add a transition for the opacity.&lt;/p&gt;
&lt;p&gt;Next the &lt;code&gt;header&lt;/code&gt; is given an opacity of 1 when the &lt;code&gt;is-visible&lt;/code&gt; class is applied.&lt;/p&gt;
&lt;p&gt;For the header image and title we&#39;d like to scale the photo and push the text down a bit. We can add styles to do this.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.main-photo&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;scale&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;.8&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.heading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-50% + 1em&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sets up the initial states of the elements. The photo is scaled down to .8 of it&#39;s normal size. The &lt;code&gt;heading&lt;/code&gt; text is pushed down 1em. I&#39;m using absolute positioning on this title text, setting the &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;top&lt;/code&gt; to 50% of the &lt;code&gt;header&lt;/code&gt;. This &lt;code&gt;transform&lt;/code&gt; corrects by pulling the text back into the center and then adding an extra &lt;code&gt;1em&lt;/code&gt; to push it down a bit.&lt;/p&gt;
&lt;p&gt;The next step is to add the styles for when the &lt;code&gt;header&lt;/code&gt; has the &lt;code&gt;is-visible&lt;/code&gt; class.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.is-visible .main-photo&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.is-visible .heading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;-50%&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; -50%&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We start with &lt;code&gt;is-visible&lt;/code&gt; then &lt;code&gt;main-photo&lt;/code&gt; to specify the photo when it&#39;s parent has the &lt;code&gt;is-visible&lt;/code&gt; class. In this state we can remove the &lt;code&gt;transform&lt;/code&gt;. For the &lt;code&gt;heading&lt;/code&gt; text we want to position it in the center of the screen.&lt;/p&gt;
&lt;p&gt;With the two states defined the last thing it to add a transition.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.main-photo,
.heading&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;transition&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transform 4s .25s &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;.3&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;will-change&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; transform&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We specify both the &lt;code&gt;main-photo&lt;/code&gt; and the &lt;code&gt;heading&lt;/code&gt;. For each of these we apply a &lt;code&gt;transition&lt;/code&gt; to the &lt;code&gt;transform&lt;/code&gt; property, with a long duration of 4 seconds, a delay as before, and the exponential ease-out timing function.&lt;/p&gt;
&lt;p&gt;We&#39;ll also add a &lt;code&gt;will-change&lt;/code&gt; property here to tell the browser to optimise the &lt;code&gt;transform&lt;/code&gt; property on these elements for animating.&lt;/p&gt;
&lt;p&gt;Let&#39;s see it in action.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;rmzNZJ&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here we see that on load, the header fades in and the photo and text transition into place. If we scroll the page we see each of the photos fading in as they enter the viewport.&lt;/p&gt;
&lt;h2 id=&quot;what-we-learned&quot; tabindex=&quot;-1&quot;&gt;What we learned&lt;/h2&gt;
&lt;p&gt;In this tutorial we were introduced to the handy &lt;code&gt;requestAnimationFrame&lt;/code&gt; method. We wrote a handy JavaScript utility to detect when an element is inside the viewport, and apply a class to it. We will be able to use this any time we want to trigger animations on an element on scroll.&lt;/p&gt;
&lt;p&gt;We also made use of the &lt;code&gt;will-change&lt;/code&gt; property, which allows us to hint to the browser which properties are going to be animated.&lt;/p&gt;
&lt;h2 id=&quot;level-up-your-css-animation-skills!&quot; tabindex=&quot;-1&quot;&gt;Level up your CSS animation skills!&lt;/h2&gt;
&lt;p&gt;If you like this, you&#39;ll love my &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;video course on CSS animation&lt;/a&gt;. As a fan of this site you can save over 90% on the course today.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;Save over 90% and Level Up Your CSS Animation Skills&lt;/a&gt; today!&lt;/p&gt;
</content>
  </entry><entry>
    <title>Parallax scrolling</title>
    <link href="https://cssanimation.rocks/parallax/"/>
    <updated>2019-05-26T00:00:00Z</updated>
    <id>https://cssanimation.rocks/parallax/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://production-assets.codepen.io/assets/embed/ei.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;Let&#39;s have some fun with parallax scrolling, using a handy JavaScript plugin called &amp;quot;Rellax&amp;quot; to animate a page with lots of elements scrolling at different speeds.&lt;/p&gt;
&lt;p&gt;For this tutorial you&#39;ll find the HTML and CSS you need to get started in &lt;a href=&quot;https://cssanimation.rocks/levelup/public/03/03.zip&quot;&gt;this sample code file&lt;/a&gt;. Look for folder &lt;code&gt;03-start&lt;/code&gt;. A completed version of this lesson&#39;s code is in the folder &lt;code&gt;03-end&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;videoWrapper&quot;&gt;
```html
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube-nocookie.com/embed/vYhmUe3nEqI&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
```
&lt;/div&gt;
&lt;h2 id=&quot;what-is-parallax%3F&quot; tabindex=&quot;-1&quot;&gt;What is parallax?&lt;/h2&gt;
&lt;p&gt;Parallax movement is when things move at different speeds relative to each other. It&#39;s a popular effect that can be used to create an illusion of depth. If we&#39;re moving, we see objects close to us move faster than objects further away.&lt;/p&gt;
&lt;p&gt;The technique is popular in many places including video games, where it&#39;s usually seen in the layered backgrounds.&lt;/p&gt;
&lt;p&gt;In this example we see how parallax works when scrolling a website.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;zwdBzP&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Each of these boxes scrolls upward as I scroll down the page. The box in the middle, marked &amp;quot;No parallax&amp;quot; is scrolling at the same speed as the page. To it&#39;s left is a box that scrolls faster, and the box on the right scrolls slower.&lt;/p&gt;
&lt;p&gt;This means that if I was to scroll the page up by 100 pixels, the &amp;quot;faster&amp;quot; box actually scrolls something like 130 pixels, and the &amp;quot;slower&amp;quot; box moves about 70 pixels.&lt;/p&gt;
&lt;p&gt;In this example I&#39;m using a tool called &lt;a href=&quot;https://dixonandmoe.com/rellax/&quot;&gt;Rellax&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;rellax&quot; tabindex=&quot;-1&quot;&gt;Rellax&lt;/h2&gt;
&lt;p&gt;The JavaScript utility Rellax is a handy, and quite simple plugin created by the design agency Dixon and Moe. It&#39;s lightweight and has no need for jQuery, and we can call it in from either local file or by using a CDN.&lt;/p&gt;
&lt;p&gt;Looking into &lt;a href=&quot;https://github.com/dixonandmoe/rellax/blob/master/rellax&quot;&gt;the code&lt;/a&gt; we find that it&#39;s using a very similar approach to our &amp;quot;show-on-scroll&amp;quot; code. It sets up a &lt;code&gt;loop&lt;/code&gt; variable using &amp;quot;requestAnimationFrame&amp;quot;, and then in each iteration uses CSS to &lt;code&gt;translate&lt;/code&gt; each object by a calculated offset.&lt;/p&gt;
&lt;p&gt;It&#39;s worth taking a look through how this was built if you&#39;d like to see how a nice simple JavaScript utility can be written and shared.&lt;/p&gt;
&lt;p&gt;Let&#39;s use it to bring our page some parallax movement.&lt;/p&gt;
&lt;h2 id=&quot;starting-page&quot; tabindex=&quot;-1&quot;&gt;Starting page&lt;/h2&gt;
&lt;p&gt;To get started we have a space-themed page taking us on a trip to the moon. Along the way we pass a bunch of rocks. We can use Rellax to have these elements scroll at different speeds.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;gWxMLJ&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We begin by adding Rellax to our page. In our &lt;code&gt;index.html&lt;/code&gt; file, just before the closing &lt;code&gt;body&lt;/code&gt; tag, add a reference to the script.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;./javascripts/rellax.min.js&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;span class=&quot;token language-javascript&quot;&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rellax &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Rellax&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;.rellax&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We also put in some JavaScript to activate Rellax. We pass the &lt;code&gt;Rellax&lt;/code&gt; method a string that will be used to identify the elements it&#39;ll need to animate. In this case, we&#39;re going to use the class &amp;quot;rellax&amp;quot; on our elements.&lt;/p&gt;
&lt;p&gt;With this in place we can add the &amp;quot;rellax&amp;quot; class. Scrolling back up the HTML we can look for each of the &lt;code&gt;floating-rocks&lt;/code&gt; elements.&lt;/p&gt;
&lt;p&gt;We add the &lt;code&gt;rellax&lt;/code&gt; class to each like so.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;floating-rocks front-one rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;images/rock1.svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the class applied to each of the rocks we can see the effect in the browser.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;xdXYKv&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So it&#39;s working, the rocks are scrolling at a slower speed than the text, but it&#39;s not right yet. All the rocks are moving at the same speed as each other. We&#39;d like to have some sit in front of the text and some behind, so let&#39;s achieve this using some Rellax settings.&lt;/p&gt;
&lt;h2 id=&quot;rellax-settings&quot; tabindex=&quot;-1&quot;&gt;Rellax settings&lt;/h2&gt;
&lt;p&gt;When working with Rellax we have two pieces of data we can pass in that will change the way the movement occurs. The first is speed.&lt;/p&gt;
&lt;p&gt;We can tell each image to scroll at a different speed. The value is an integer where a negative number means it&#39;ll move more slowly than the normal scroll speed, and a positive number means it&#39;ll move at the same speed or faster.&lt;/p&gt;
&lt;p&gt;In our HTML we again go to each of the images but this time add a speed. It&#39;s written as a &lt;code&gt;data&lt;/code&gt; attribute &lt;code&gt;data-rellax-speed&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;floating-rocks front-one rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-rellax-speed&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;8&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;images/rock1.svg&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first rock is a small one that sits in front so we&#39;ll give it a fast speed of &amp;quot;8&amp;quot;. The second one is far back so it&#39;s going to have a speed of &amp;quot;-2&amp;quot;. The next one in front again, so we&#39;ll give a positive value of &amp;quot;3&amp;quot;. The next rock is also far back so we&#39;ll give it a speed of &amp;quot;-3&amp;quot;.&lt;/p&gt;
&lt;p&gt;Lastly for planet earth we&#39;ll set it far back into the scene with a speed of &amp;quot;-4&amp;quot;.&lt;/p&gt;
&lt;p&gt;There&#39;s one more thing, &amp;quot;centering&amp;quot;.&lt;/p&gt;
&lt;p&gt;When Rellax calculates how far to move the elements it does so based on the height of the page. This means that elements further down the page will have moved more than elements at the top, as by the time we&#39;ve scrolled all the way down there, they&#39;ve been parallaxed to somewhere we may not expect.&lt;/p&gt;
&lt;p&gt;We can get around this using centering. This will adjust the element&#39;s position so that when we scroll to it, it&#39;ll still be visible on the page. We can either do this by adding a &lt;code&gt;data-rellax-percentage&lt;/code&gt; value to each of the rocks, or we can set this globally in our original JavaScript at the bottom of the page.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;span class=&quot;token language-javascript&quot;&gt;
  &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rellax &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Rellax&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;.rellax&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;center&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In our JavaScript we add an object to be passed in to the &lt;code&gt;Rellax&lt;/code&gt; method and in it we specify &amp;quot;center&amp;quot; be true. Back in our browser we can see the results.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;PmJQPj&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The rocks now float in front as well as far away behind the text.&lt;/p&gt;
&lt;p&gt;Before we finish up this example, let&#39;s also see how Rellax can bring our header and footer elements to life.&lt;/p&gt;
&lt;h2 id=&quot;animating-the-header-and-footer&quot; tabindex=&quot;-1&quot;&gt;Animating the header and footer&lt;/h2&gt;
&lt;p&gt;At the top our document we have a &lt;code&gt;header&lt;/code&gt; element containing an SVG logo and heading text. The SVG is inline so we can apply Rellax to each of the individual parts. That way on scroll, the logo will come apart as it scrolls away.&lt;/p&gt;
&lt;p&gt;We start with the two &lt;code&gt;circle&lt;/code&gt; elements.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;circle&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-rellax-speed&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;-1&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;#000000&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;stroke-width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;3&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;#333333&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;cx&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100.5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;cy&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100.5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100.5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;circle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;circle&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-rellax-speed&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;-.5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;stroke&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;#000000&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;stroke-width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;3&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;#aaa&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token special-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token value css language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;opacity&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0.9&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;cx&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;100.5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;cy&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;99.225&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;79.875&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;circle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Adding a class of &amp;quot;rellax&amp;quot; to each we can specify speeds. These two are farthest away so we&#39;ll use negative values of &amp;quot;-1&amp;quot; and &amp;quot;-.5&amp;quot; so they move quite slowly.&lt;/p&gt;
&lt;p&gt;Next we have some &lt;code&gt;&amp;lt;g&amp;gt;&lt;/code&gt; groups we can use to hook Rellax onto. The first contains the large boulder. We&#39;ll use this containing &lt;code&gt;&amp;lt;g&amp;gt;&lt;/code&gt; rather than the &lt;code&gt;large-boulder&lt;/code&gt; group as there&#39;s already a &lt;code&gt;transform&lt;/code&gt; on that group. Since Rellax uses transforms, this would cause a clash so it&#39;s safest to use the container.&lt;/p&gt;
&lt;p&gt;We&#39;ll add the &amp;quot;rellax&amp;quot; class and give this a speed of &amp;quot;2&amp;quot;.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;g&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-rellax-speed&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We then do the same for the &amp;quot;medium-boulder&amp;quot; and &amp;quot;small-boulder&amp;quot; containers, giving them a speed of &amp;quot;1.5&amp;quot; and &amp;quot;1.25&amp;quot; so that they move a little slower than the large boulder.&lt;/p&gt;
&lt;p&gt;With that done lets add parallax to the heading. There&#39;s a gradient on the &lt;code&gt;header&lt;/code&gt; element at the bottom that makes it fade to black. It would be cool if this text was to scroll in behind that gradient. We can do this by giving the title a very slow scroll speed.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;heading rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-rellax-speed&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;-5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;MOON ROCKS&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lastly let&#39;s do the same with the header at the bottom of the page. Inside the &lt;code&gt;footer&lt;/code&gt; element we apply the same thing but a speed of &amp;quot;-2&amp;quot; to the heading.&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;heading rellax&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-rellax-speed&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;-2&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;MOON ROCKS&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&#39;s see how this is looking.&lt;/p&gt;
&lt;p data-height=&quot;600&quot; data-theme-id=&quot;light&quot; data-slug-hash=&quot;ZKJOBe&quot; data-default-tab=&quot;result&quot; data-user=&quot;donovanh&quot; data-embed-version=&quot;2&quot; data-pen-title=&quot;&quot; class=&quot;codepen&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 id=&quot;fixing-the-header&quot; tabindex=&quot;-1&quot;&gt;Fixing the header&lt;/h2&gt;
&lt;p&gt;After recording this lesson I noticed that the &amp;quot;center&amp;quot; setting caused the header and footer elements to position wrongly. Turns out the header elements don&#39;t need this to be set, and we can get around this by declaring another set of &amp;quot;Rellax&amp;quot; elements in the JavaScript.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; rellaxNonCentered &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Rellax&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;.rellax-non-centered&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;center&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By using the class &amp;quot;rellax-non-centered&amp;quot; on the header and footer elements instead of &amp;quot;rellax&amp;quot;, this should fix the issue! The code in the &lt;a href=&quot;https://cssanimation.rocks/levelup/public/03/03.zip&quot;&gt;download zip file&lt;/a&gt; has been updated with this change.&lt;/p&gt;
&lt;h2 id=&quot;parallax-using-css&quot; tabindex=&quot;-1&quot;&gt;Parallax using CSS&lt;/h2&gt;
&lt;p&gt;While this example uses CSS and JavaScript for the positioning of the elements on scroll, it&#39;s possible to create a parallax effect using pure CSS. There&#39;s a &lt;a href=&quot;https://developers.google.com/web/updates/2016/12/performant-parallaxing&quot;&gt;great write-up of this approach&lt;/a&gt; by Paul Lewis and Robert Flack that goes into more detail. It&#39;s a great approach and seems to perform well.&lt;/p&gt;
&lt;h2 id=&quot;what-we-learned&quot; tabindex=&quot;-1&quot;&gt;What we learned&lt;/h2&gt;
&lt;p&gt;In this lesson we made use of a great JavaScript tool to create parallax movement on our page. Along the way we saw how this tool uses CSS transforms to move elements on scroll, using a similar &lt;code&gt;requestAnimationFrame&lt;/code&gt; approach we&#39;ve used ourselves. We also learned how to use Rellax with various speeds to create the illusion of depth on the page.&lt;/p&gt;
&lt;h2 id=&quot;level-up-your-css-animation-skills!&quot; tabindex=&quot;-1&quot;&gt;Level up your CSS animation skills!&lt;/h2&gt;
&lt;p&gt;If you like this, you&#39;ll love my &lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;video course on CSS animation&lt;/a&gt;. As a fan of this site you can save over 90% on the course today.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.udemy.com/course/level-up-your-css-animation-skills/?referralCode=D358C1EDAB25E718B07A&quot;&gt;Save over 90% and Level Up Your CSS Animation Skills&lt;/a&gt; today!&lt;/p&gt;
</content>
  </entry>
</feed>