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 id="app" data-state="closed">
  <!--   Content -->
  <section class="app-content">
    <span class="bg"></span>
    <div>
      <h1>Sidebar notification layout</h1>
    <p>Responsive notification element that can be toggled to a sidebar</p>
    <figure>
    <img src="https://images.unsplash.com/photo-1592438097191-82d15d527dba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=80" alt="A black unicorn on pink background">
      <figcaption>A little magic on the side</figcaption>
    </figure>
    </div>
  </section>

  <!--   Notification -->
  <aside id="notification" class="notification" style="--image: url(https://images.unsplash.com/photo-1582343104600-6d1fe40281fc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=933&q=80);">
    <span class="bg"></span>
    <h2 class="notification-header">2 new messages</h2>
    <div class="notification-content">
      <ol class="notification-list">
        <li>Hi! 👋</li>
        <li>10 things all the cool kids are doing today 😎</li>
      </ol>
    </div>
  </aside>
</main>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=PT+Sans:wght@400;700&display=swap");

:root {
  --black: hsl(3, 3%, 4%);
  --white: hsl(0, 3%, 98%);
  --gray: hsl(3, 3%, 88%);
  --blue: #74c0fc;
  --yellow: #ffe066;
  --red: #ffa8a8;
  --green: #51cf66;
  --font: "PT Sans", sans-serif;
  --notification-width: 15rem;
  --gradient-bg: radial-gradient(
      circle at top left,
      var(--blue),
      var(--yellow) 60%,
      var(--red)
    )
    no-repeat center center/cover;
  --icon-mail: #{url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 7.921l8.427 5.899c0.34 0.235 0.795 0.246 1.147 0l8.426-5.899v10.079c0 0.272-0.11 0.521-0.295 0.705s-0.433 0.295-0.705 0.295h-16c-0.272 0-0.521-0.11-0.705-0.295s-0.295-0.433-0.295-0.705zM1 5.983c0 0.010 0 0.020 0 0.030v11.987c0 0.828 0.34 1.579 0.88 2.12s1.292 0.88 2.12 0.88h16c0.828 0 1.579-0.34 2.12-0.88s0.88-1.292 0.88-2.12v-11.988c0-0.010 0-0.020 0-0.030-0.005-0.821-0.343-1.565-0.88-2.102-0.541-0.54-1.292-0.88-2.12-0.88h-16c-0.828 0-1.579 0.34-2.12 0.88-0.537 0.537-0.875 1.281-0.88 2.103zM20.894 5.554l-8.894 6.225-8.894-6.225c0.048-0.096 0.112-0.183 0.188-0.259 0.185-0.185 0.434-0.295 0.706-0.295h16c0.272 0 0.521 0.11 0.705 0.295 0.076 0.076 0.14 0.164 0.188 0.259z"></path></svg>')};
  --icon-close: #{url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5.293 6.707l5.293 5.293-5.293 5.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0l5.293-5.293 5.293 5.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-5.293-5.293 5.293-5.293c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-5.293 5.293-5.293-5.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414z"></path></svg>')};
}

* {
  transition-property: var(--property, none);
  transition-duration: var(--duration, 0s);
  transition-delay: var(--delay, 0s);
  transition-timing-function: var(--ease, linear);

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

html {
  &,
  body {
    height: 100%;
  }

  body {
    margin: 0;
    background: var(--white);
    color: var(--black);
    font-family: var(--font);
  }

  figure {
    margin: 0;
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;

    figcaption {
      padding: 0.5em;
      margin: 1em;
      background: var(--gray);
      border-radius: 0.5em;
    }
  }

  img {
    max-width: 100%;
  }
}

[data-state="closed"] {
  --area: 1 / 2;
  --border: 5px;
}

[data-state="opened"] {
  --area: 1 / 2 / 3;
  --shadow: -1px 0 4px var(--gray);

  // To push content aside
  @media screen and (min-width: 60rem) {
    --area: 1 / 3 / 3;
    --shadow: none;
  }
}

#app {
  min-height: 100vh;
  background: var(--gradient-bg);
  display: grid;

  // @media screen and (min-width: 60rem) {
  //   grid-template-columns: repeat(2, 1fr) auto;
  // }
}

.app-content {
  --bg: var(--white);
  grid-area: 1 / 1 / 3 / 3;
  margin: 2rem;
  padding: 2rem;
  position: relative;

  & > * {
    z-index: 1;
    position: relative;
  }

  .bg {
    z-index: 0;
    border-radius: 5px;
    transform: none;
    transform-origin: top left;
    --property: transform;
    --duration: 0.3s;
  }

  &[data-flipping] {
    .bg {
      transition: none;
      transform: scaleX(calc(1 / var(--dw)));
    }
  }

  h1 {
    margin: 0 0 0.5em;
  }
}

.notification {
  --bg: var(--white);
  position: relative;
  grid-area: var(--area);
  border-radius: var(--border);
  box-shadow: var(--shadow);
  z-index: 2;
  --property: border-radius, margin, box-shadow;
  --duration: 0.2s, 1s, 0.5s;
  --ease: cubic-bezier(0.55, 1, 0.68, 0.53);

  .bg {
    transform: none;
    transform-origin: top right;
    border-radius: inherit;
    --property: transform;
    --duration: 0.3s;
  }

  &[data-flipping] {
    transition: none;
    transform: translate(calc(var(--dx) * -1px), calc(var(--dy) * -1px));

    .bg {
      transition: none;
      transform: scale(calc(1 / var(--dw)), calc(1 / var(--dh)));
    }
  }

  [data-state="closed"] & {
    justify-self: end;
    align-self: start;
    margin: 1rem;
    --shadow: 0px 0 3px var(--gray), 0 0 3px hsla(0, 3%, 5%, 0.6);
  }

  &-header {
    --icon-size: 1.3rem;
    margin: 0;
    padding: 0.5em;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    border-radius: var(--border);

    &::before,
    &::after {
      content: "";
      width: 0;
      height: 0;
      padding: calc(var(--icon-size) / 2);
      mask: var(--icon) no-repeat center center/contain;
    }

    &::before {
      --icon: var(--icon-mail);
      background: var(--green);
      margin-right: 0.5em;
    }

    &::after {
      --icon: var(--icon-close);
      background: var(--black);
      margin-left: 0.5em;
    }

    [data-state="closed"] & {
      &::after {
        display: none;
      }
    }
  }

  &-content {
    min-width: var(--notification-width);
    opacity: 0;
    border-top: 1px solid var(--gray);
    animation: 0.3s appear 0.4s ease-in forwards;

    [data-state="closed"] & {
      display: none;
    }
  }

  &-list {
    margin: 0;
    padding: 0;
    list-style: none;

    li {
      margin: 0.5em;
      padding: 0.5rem;
      border: 1px solid var(--gray);
      border-radius: 5px;
    }
  }
}

.bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  z-index: -1;
}

@keyframes appear {
  to {
    transform: none;
    opacity: 1;
  }
}

              
            
!

JS

              
                console.clear();
const appEl = document.querySelector("#app");
const notificationEl = appEl.querySelector(".notification");
const toggleEl = notificationEl.querySelector(".notification-header");

// Add click even listener to toggle state
toggleEl.addEventListener("click", () => {
  // Usi FLIP to trigger animations
  flip(() => {
    appEl.dataset.state = appEl.dataset.state === "closed" ? "opened" : "closed";
  }, notificationEl)
  // Add flip to content
  flip(() => {}, appEl.querySelector('.app-content'));
});

// F.L.I.P
const flip = (doSomething, firstEl, getLastEl = () => firstEl) => {
  // First
  const firstElRect = firstEl.getBoundingClientRect();

  requestAnimationFrame(() => {
    doSomething();

    // Last
    let lastEl = getLastEl();
    const lastElRect = lastEl.getBoundingClientRect();

    // Invert
    const dx = lastElRect.x - firstElRect.x;
    const dy = lastElRect.y - firstElRect.y;
    const dw = lastElRect.width / firstElRect.width;
    const dh = lastElRect.height / firstElRect.height;

    console.log({ dx, dy, dh, dw });

    lastEl.dataset.flipping = true;
    lastEl.style.setProperty("--dx", dx);
    lastEl.style.setProperty("--dy", dy);
    lastEl.style.setProperty("--dw", dw);
    lastEl.style.setProperty("--dh", dh);

    // Play
    requestAnimationFrame(() => {
      delete lastEl.dataset.flipping;
    });
  });
};

              
            
!
999px

Console