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

              
                <header>
  <svg class="display" viewBox="0 0 520 90">
    <text x="0" y="65">Don't <tspan class="text-primary col-4">SQUISH</tspan> me!</text>
  </svg>
</header>

<div class="squishy-container">
  <!-- squishy-template inserted here -->
</div>

<div class="button-container">
  <button id="addSquishy" type="button">
    Add squishy
  </button>
  <button id="resetSquishies" type="button">
    Reset
  </button>
</div>

<template id="squishy-template">
  <div data-index="0" class="squishy">
    <div class="squishy-body">
      <div class="squishy-face">
        <svg class="squishy-face-0" width="36" height="12" viewBox="0 0 36 12" fill="none">
          <circle cx="4" cy="4" r="4" fill="#231F20" />
          <circle cx="32" cy="4" r="4" fill="#231F20" />
          <path d="M13 7L13.2065 7.45433C15.0205 11.445 20.7263 11.3357 22.3861 7.27847L22.5 7" stroke="#231F20" stroke-width="2" stroke-linecap="round" />
        </svg>
        <svg class="squishy-face-1" width="36" height="12" viewBox="0 0 36 12" fill="none" xmlns="http://www.w3.org/2000/svg">
          <circle cx="4" cy="4" r="4" fill="#231F20" />
          <circle cx="32" cy="4" r="4" fill="#231F20" />
          <path d="M24 9L12 9" stroke="#231F20" stroke-width="2" stroke-linecap="round" />
        </svg>
        <svg class="squishy-face-2" width="36" height="12" viewBox="0 0 36 12" fill="none">
          <circle cx="4" cy="4" r="4" fill="#231F20" />
          <circle cx="32" cy="4" r="4" fill="#231F20" />
          <path d="M22.6593 10.5882L13 8" stroke="#231F20" stroke-width="2" stroke-linecap="round" />
        </svg>
        <svg class="squishy-face-3" width="36" height="12" viewBox="0 0 36 12" fill="none">
          <circle cx="4" cy="4" r="4" fill="#231F20" />
          <circle cx="32" cy="4" r="4" fill="#231F20" />
          <path d="M22.5 11L22.2935 10.5457C20.4795 6.55496 14.7737 6.66426 13.1139 10.7215L13 11" stroke="#231F20" stroke-width="2" stroke-linecap="round" />
        </svg>
        <svg class="squishy-face-4" width="39" height="12" viewBox="0 0 39 12" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M10.6593 3.58819L1 1" stroke="#000000" stroke-width="2" stroke-linecap="round" />
          <circle cx="5" cy="6" r="4" fill="#000000" />
          <circle cx="33" cy="6" r="4" fill="#000000" />
          <path d="M37.6593 1.00001L28 3.5882" stroke="#000000" stroke-width="2" stroke-linecap="round" />
          <path d="M23.5 11L23.2935 10.5457C21.4795 6.55496 15.7737 6.66426 14.1139 10.7215L14 11" stroke="#000000" stroke-width="2" stroke-linecap="round" />
        </svg>
      </div>
    </div>
  </div>
</template>
              
            
!

CSS

              
                $bg-color: #fdf7ce;
$primary: white;
$accent: yellow;
$text-col: #231f20;
$face-col-0: #85de77;
$face-col-1: #fdfd97;
$face-col-2: #feb144;
$face-col-3: #ff6663;
$face-col-4: #ff0000;
$largest-width: "275px";

@import url("https://fonts.googleapis.com/css2?family=Sniglet:wght@400;800&display=swap");

* {
  box-sizing: border-box;
}

body {
  align-items: center;
  background-color: $bg-color;
  display: flex;
  flex-direction: column;
  font-family: "Sniglet", cursive;
  justify-content: center;
  gap: 20px;
  margin: 20px 0;
  padding: 0;
  width: 100vw;
}
.col-0 {
  fill: $face-col-0;
}

.col-1 {
  fill: $face-col-1;
}

.col-2 {
  fill: $face-col-2;
}

.col-3 {
  fill: $face-col-3;
}

.col-4 {
  fill: $face-col-4;
}

svg.display {
  width: 100%;
  height: 70px;

  text {
    font-size: 60px;
    letter-spacing: 0px;
    fill: $text-col;
    stroke-linejoin: round;
  }

  tspan.text-primary {
    font-weight: 800;
    stroke: $text-col;
    stroke-width: 5px;
  }
}
.button-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
button#addSquishy {
  border: 0;
  background: white;
  border-radius: 999px;
  font-family: "Sniglet", cursive;
  font-size: 1.5em;
  padding: 1rem 2rem;
  border: 3px solid $text-col;
  box-shadow: 0 5px $text-col;
  transition: 0.2s;
  cursor: pointer;
  color: $text-col;
  &:hover {
    box-shadow: 0 3px $text-col;
    transform: translateY(2px);
  }
  &:active {
    box-shadow: 0 0px $text-col;
    transform: translateY(5px);
  }
}
button#resetSquishies {
  font-family: "Sniglet", cursive;
  color: $text-col;
  border: 0;
  background: none;
  cursor: pointer;

  &:hover {
    text-decoration: underline;
  }
}

.squishy-container {
  background: linear-gradient($text-col, $text-col) 0 20% / 10% 5px,
    linear-gradient($text-col, $text-col) 100% 20% / 70% 5px,
    linear-gradient($text-col, $text-col) 0 50% / 70% 5px,
    linear-gradient($text-col, $text-col) 100% 50% / 10% 5px,
    linear-gradient($text-col, $text-col) 0 80% / 40% 5px,
    linear-gradient($text-col, $text-col) 100% 80% / 40% 5px;
  background-color: #ba7a45;
  background-repeat: no-repeat;
  border: 5px solid $text-col;
  border-radius: 35px;
  box-shadow: 0 5px $text-col;
  padding: 1rem;
  height: calc(200px + 10px);
  width: 85%;
  display: flex;
  justify-content: flex-start;
  gap: 5px;
  resize: horizontal;
  overflow: auto;
}
.squishy {
  transition: 0.3s;
  container-type: inline-size;
  flex: 1 0 auto;
  cursor: pointer;
  height: calc(200px - 2rem);
}

@mixin show-squishy-face($index) {
  @for $i from 0 through 4 {
    @if $i == $index {
      .squishy-face-#{$i} {
        display: block;
      }
    } @else {
      .squishy-face-#{$i} {
        display: none;
      }
    }
  }
}

.squishy-body {
  border-radius: 35px;
  border: 5px solid $text-col;
  box-shadow: 0 3px $text-col;
  height: 100%;
  position: relative;
  //THE CONTAINER QUERY BIT
  background-color: $face-col-4;
  @include show-squishy-face(4);

  @container (min-width: calc(#{$largest-width} / 4)) {
    background-color: $face-col-3;
    @include show-squishy-face(3);
  }

  @container (min-width: calc(#{$largest-width} / 3)) {
    background-color: $face-col-2;
    @include show-squishy-face(2);
  }

  @container (min-width: calc(#{$largest-width} / 2)) {
    background-color: $face-col-1;
    @include show-squishy-face(1);
  }

  @container (min-width: #{$largest-width}) {
    background-color: $face-col-0;
    @include show-squishy-face(0);
  }
}

.squishy-face {
  width: 100%;
  max-width: 100px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -8px);

  > svg {
    width: 100%;
    height: auto;
    margin: auto 0;
  }
}

.squishy-body svg {
  [stroke^="#"] {
    stroke: $text-col;
  }

  [fill^="#"] {
    fill: $text-col;
  }
}

              
            
!

JS

              
                //JS just to handle adding and removing squishies
function addSquishy() {
  let squishyTemplate = document.querySelector("#squishy-template");
  let squishy = document.importNode(squishyTemplate.content, true);
  let newSquishy = squishy.querySelector(".squishy");
  newSquishy.onclick = function () {
    this.remove();
  };
  document.querySelector(".squishy-container").appendChild(newSquishy);
}

addSquishy();

document.querySelector(".squishy").addEventListener("click", function () {
  this.remove();
});

document.querySelector("#addSquishy").addEventListener("click", () => {
  addSquishy();
});

document.querySelector("#resetSquishies").addEventListener("click", () => {
  document.querySelector(".squishy-container").innerHTML = "";
  addSquishy();
});

              
            
!
999px

Console