Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main class="wrapper">
  <div class="row">
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
  </div>
</main>
<div class="info">
  <p>
    <a href="https://muffinman.io/blog/css-blocky-people-making-waves/" target="_blank">Read the blog post</a>
  </p>
  <p>
    For performance reasons this animation is best viewed in Safari. To add a
    blocky person <button class="add-more-button">click here</button>.
  </p>

  <div class="country-select">
    <div class="title">World Cup bonus:</div>
    <label>
      <input type="radio" name="country" value="random" checked> Random colors
    </label>
    <label>
      <input type="radio" name="country" value="brazil"> Brazil
    </label>
    <label>
      <input type="radio" name="country" value="denmark"> Denmark
    </label>
    <label>
      <input type="radio" name="country" value="netherlands"> Netherlands
    </label>
    <label>
      <input type="radio" name="country" value="serbia"> Serbia
    </label>
    <label>
      <input type="radio" name="country" value="usa"> USA
    </label>
  </div>
</div>
              
            
!

CSS

              
                *,
*::after,
*::before {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial,
    sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

html {
  font-size: 1px;
}

@media (min-width: 600px) {
  html {
    font-size: 1.5px;
  }
}

@media (min-width: 1000px) {
  html {
    font-size: 2px;
  }
}

@media (min-width: 1400px) {
  html {
    font-size: 3px;
  }
}

body {
  line-height: 1.4em;
  text-align: center;
  background-color: #6c86a0;
  color: #fff;
  font-size: 16px;
  padding: 100rem 20px 100rem;
}

.wrapper {
  transform-style: preserve-3d;
  transform: rotateY(60deg) rotateX(5deg);
  margin-bottom: 50px;

  * {
    transform-style: preserve-3d;
  }
}

.info {
  max-width: 400px;
  margin: 0 auto;
}

p {
  margin-bottom: 15px;
}

.country-select label {
  display: block;
}

.title {
  font-weight: bold;
  margin-bottom: 5px;
}

a,
button {
  color: #fff;
  background: none;
  padding: 0;
  border: none;
  text-decoration: underline;
  font-size: 16px;
  cursor: pointer;
  transition: color 300ms, border-color 300ms;

  &:hover {
    color: #78d9bd;
    border-bottom-color: #78d9bd;
  }
}

// -------- BOX

css-box {
  display: block;
  position: relative;

  > div {
    position: absolute;
    border: 1rem solid rgba(black, 0.2);
    background: white;
    backface-visibility: hidden;
  }
}

@mixin box($width, $height, $depth) {
  width: $width;
  height: $height;

  .left,
  .right {
    width: $depth;
    height: $height;
  }

  .front,
  .back {
    width: $width;
    height: $height;
  }

  .top,
  .bottom {
    width: $width;
    height: $depth;
  }

  .front {
    transform: translateZ($depth / 2);
  }

  .back {
    transform: translateZ($depth / -2) rotateY(180deg);
  }

  .left {
    transform: translateX($depth / -2) rotateY(270deg);
  }

  .right {
    transform: translateX($width - $depth / 2) rotateY(90deg);
  }

  .top {
    transform: translateY($depth / -2) rotateX(90deg);
  }

  .bottom {
    transform: translateY($height - $depth / 2) rotateX(-90deg);
  }
}

$time: 3s;

// ------------- ROW

.row {
  display: flex;
  justify-content: center;
  width: 500vw;
  margin-left: -200vw;
}

// ------------- PERSON

css-person {
  display: flex;
  flex-wrap: wrap;
  width: 54rem;
  margin-right: 12rem;
}

$tshirt-colors: #9b59b7, #1abc9d, #e74c3c, #f1c40f, #3498db, #e67e22, #34495e;
$shoes-colors: #2b071f, #ffe600, #345, #ecf0f1, #0abde3, #6c5ce7;
$pants-colors: #1e3799, #198066, #510b6d, #2c3e50, #d35400, #95a5a6;
$skin-colors: #d8b997, #bb9472, #966946, #473a30;

@for $i from 1 through 30 {
  css-person:nth-child(#{$i}) {
    &,
    & * {
      animation-delay: $i * 0.3s;
    }

    $tshirt-color: nth($tshirt-colors, random(length($tshirt-colors)));
    $shoes-color: nth($shoes-colors, random(length($shoes-colors)));
    $pants-color: nth($pants-colors, random(length($pants-colors)));
    $skin-color: nth($skin-colors, random(length($skin-colors)));

    .head *,
    .arm-bottom * {
      background: $skin-color;
    }

    .torso *,
    .arm-top * {
      background: $tshirt-color;
    }

    .leg-top *,
    .leg-bottom * {
      background-color: $pants-color;
    }

    .leg-shoe * {
      background-color: $shoes-color;
    }
  }
}

// ------------- TOP

@keyframes person-top {
  0% {
    transform: translateZ(-7rem) translateY(-15rem) rotateX(-5deg);
  }
  50% {
    transform: translateZ(16rem) translateY(-33rem) rotateX(0deg);
  }
}

.person-top {
  display: flex;
  flex-wrap: wrap;
  transform: translateZ(-7rem) translateY(-15rem) rotateX(-5deg);
  animation: person-top $time ease-in-out infinite;
}

// ------------- HEAD

.head-wrapper {
  flex-basis: 100%;
  margin-bottom: 2rem;
}

@keyframes head {
  0% {
    transform: rotateX(3deg);
  }
  50% {
    transform: rotateX(7deg);
  }
}

.head {
  @include box(15rem, 20rem, 15rem);
  margin: 0 auto;
  transform: rotateX(3deg);
  animation: head $time ease-in-out infinite;
}

// ------------- TORSO

.torso {
  @include box(30rem, 45rem, 15rem);
  margin: 0 2rem;
  position: relative;
  z-index: 100;
}

// ------------- ARMS

@keyframes arm {
  0% {
    transform: translateZ(-4rem) rotateX(60deg);
  }
  50% {
    transform: translateZ(-4rem) rotateX(150deg);
  }
}

.arm {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  transform-origin: top center;
  transform: translateZ(-4rem) rotateX(60deg);
  animation: arm $time ease-in-out infinite;
  margin-top: 10rem;
}

@keyframes arm-top {
  0% {
    transform: rotateX(-40deg);
  }
  50% {
    transform: rotateX(0deg);
  }
}

.arm-top {
  @include box(10rem, 30rem, 10rem);
  transform: rotateX(-40deg);
  animation: arm-top $time ease-in-out infinite;
  position: relative;
  z-index: 50;
}

@keyframes arm-bottom {
  0% {
    transform: rotateX(40deg);
  }
  50% {
    transform: rotateX(0deg) translateZ(0rem);
  }
}

.arm-bottom {
  @include box(9rem, 30rem, 9rem);
  margin-top: -4rem;
  transform: rotateX(40deg);
  animation: arm-bottom $time ease-in-out infinite;
}

// ------------- LEGS

.legs {
  flex-basis: 100%;
  display: flex;
  justify-content: center;
  margin-top: -18rem;
  transform: translateZ(18rem) translateY(-14rem);
}

.leg {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.leg-left {
  margin-right: 2rem;
}

@keyframes leg-top {
  0% {
    transform: translateZ(-15rem) rotateX(-10deg);
  }
  50% {
    transform: translateZ(-6rem) translateY(-15rem) rotateX(-88deg);
  }
}

.leg-top {
  @include box(12rem, 12rem, 40rem);
  transform-origin: bottom center;
  transform: translateZ(-15rem) rotateX(-10deg);
  animation: leg-top $time ease-in-out infinite;
  position: relative;
  z-index: 50;
}

@keyframes leg-bottom {
  0% {
    transform: rotateX(-15deg);
  }
  50% {
    transform: rotateX(-2deg) translateY(-2rem);
  }
}

.leg-bottom {
  @include box(10rem, 30rem, 10rem);
  transform: rotateX(-15deg);
  animation: leg-bottom $time ease-in-out infinite;
}

@keyframes leg-shoe {
  0% {
    transform: translateZ(3rem);
  }
  50% {
    transform: translateZ(3rem) translateY(-2rem) rotateX(-15deg);
  }
}

.leg-shoe {
  @include box(11rem, 8rem, 20rem);
  animation: leg-shoe $time ease-in-out infinite;
  transform: translateZ(3rem);
}


// ------- BONUS - World cup fans

@mixin fan($tshirt-color, $pants-color) {
  $shoes-color: nth($shoes-colors, random(length($shoes-colors)));
  $skin-color: nth($skin-colors, random(length($skin-colors)));

  .head *,
  .arm-bottom * {
    background: $skin-color;
  }

  .torso *,
  .arm-top * {
    background: $tshirt-color;
  }

  .leg-top * {
    background-color: $pants-color;
  }

  .leg-bottom * {
    background-color: $skin-color;
  }

  .leg-shoe * {
    background-color: $shoes-color;
  }
}

@for $i from 1 through 30 {
  css-person:nth-child(#{$i}).serbia {
    @include fan(#c21f19, #b9140e);
  }

  css-person:nth-child(#{$i}).denmark {
    @include fan(#aa2d29, #f2f3f3);
  }

  css-person:nth-child(#{$i}).usa {
    @include fan(#f2f3f3, #2e3660);
  }

  css-person:nth-child(#{$i}).brazil {
    @include fan(#eac856, #2e5cd7);
  }
  
  css-person:nth-child(#{$i}).netherlands {
    @include fan(#ea6f2d, #f2f3f3);
  }
}


              
            
!

JS

              
                class Box extends HTMLElement {
  constructor() {
    super();

    this.innerHTML = `<div class="front"></div>
      <div class="back"></div>
      <div class="right"></div>
      <div class="left"></div>
      <div class="bottom"></div>
      <div class="top"></div>`;
  }
}

window.customElements.define("css-box", Box);

class Person extends HTMLElement {
  constructor() {
    super();

    this.innerHTML = `<div class="person-top">
      <div class="head-wrapper">
        <css-box class="head"></css-box>
      </div>
      <div class="arm">
        <css-box class="arm-top"></css-box>
        <css-box class="arm-bottom"></css-box>
      </div>
      <css-box class="torso"></css-box>
      <div class="arm arm-right">
        <css-box class="arm-top"></css-box>
        <css-box class="arm-bottom"></css-box>
      </div>
    </div>
    <div class="legs">
      <div class="leg leg-left">
        <css-box class="leg-top"></css-box>
        <css-box class="leg-bottom"></css-box>
        <css-box class="leg-shoe"></css-box>
      </div>
      <div class="leg leg-right">
        <css-box class="leg-top"></css-box>
        <css-box class="leg-bottom"></css-box>
        <css-box class="leg-shoe"></css-box>
      </div>
    </div>`;
  }
}

window.customElements.define("css-person", Person);

const addMoreButton = document.querySelector(".add-more-button");
const row = document.querySelector(".row");

addMoreButton.addEventListener("click", () => {
  if (document.querySelectorAll("css-person").length >= 30) {
    return;
  }
  
  const selectedCountry = document.querySelector('input[name=country]:checked').value;
  row.innerHTML += `<css-person class="${selectedCountry}"></css-person>`;
});

// Add more people on safari
const ua = navigator.userAgent.toLowerCase();

if (ua.indexOf("safari") > -1) {
  if (ua.indexOf("chrome") > -1) {
    // Chrome
  } else {
    row.innerHTML += `<css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>
    <css-person></css-person>`;
  }
}

// -------- For debug purposes -------- //

// const wrapper = document.querySelector('.wrapper');

// window.addEventListener('mousemove', (e) => {
//   wrapper.style.transform = `rotateY(${
//     (e.clientX / window.innerWidth) * 360
//   }deg) rotateX(5deg)`;
// });

// -------- BONUS - World cup fans -------- //


const countryInputs = document.querySelectorAll('input[name=country]');

// Update colors on refresh if needed
const fans = document.querySelectorAll('css-person');
const selectedCountry = document.querySelector('input[name=country]:checked').value;

fans.forEach(function (fan) {
  fan.className = selectedCountry;
});

// Update colors on radio input change
countryInputs.forEach((input) => {
  input.addEventListener('change', function(e) {
    const fans = document.querySelectorAll('css-person');
    
    fans.forEach(function (fan) {
      fan.className = e.target.value;
    });
  });
});
              
            
!
999px

Console