<header>
  <button class="button">Flip.fit() - fit child</button>
</header>

<div class="boxes">

  <div class="target"></div>

  <div class="container">
    container
    <div class="child1">child1
    </div>
    <div class="child2">child2
    </div>
  </div>
</div>
* {
  box-sizing: border-box;
}

body {
  display: grid;
  grid-template-rows: 300px 1fr;
  justify-items: stretch;
  align-items: center;
  overflow: hidden; /* otherwise, if the scrollbar disappears as a result of the tween, the viewport actually gets resized, meaning the measurements are different! */
}

header {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.boxes {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.target {
  position: relative;
  background: var(--color-ui-gradient);
  width: 250px;
  height: 120px;
  text-align: center;
  border-radius: 10px;
  color: var(--color-just-black);
}

.container {
  width: 40%;
  border-radius: 10px;
  border: 2px dashed var(--color-surface-white);
  text-align: center;
  padding: 15px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-wrap: wrap;
}
.child1, .child2 {
  background: var(--gradient-summer-fair);
  height: 120px;
  width: 250px;
  text-align: center;
  margin: 15px 0;
  line-height: 100%;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-just-black);
}

.child1 {
  background: transparent;
  border: 2px dashed var(--color-surface-white);
}

h1 {
  font-weight: 400;
}

.button {
  padding: 10px 20px;
  margin-bottom: 10px;
}
.logo {
  position: absolute;
  width: 60px;
  bottom: 20px;
  right: 30px;
}

.target:after {
  content: "target";
  position: absolute;
  bottom: 100%;
  padding-bottom: 0.5rem;
  left: 5px;
  color: #888;
  font-size: 0.75em;
}
gsap.registerPlugin(Flip);

gsap.to(".container", { rotation: 25});
gsap.to(".target", {scale: 1.2, rotation: -18, x: 60, y: 60});

document.querySelector("button").addEventListener("click", () => {
  Flip.fit(".container", ".target", {
    fitChild: ".child1",
    scale: true, 
    duration: 2, 
    ease: "power1.inOut"
  });
});

View Compiled

External CSS

  1. https://codepen.io/GreenSock/pen/wvZQKQP.css

External JavaScript

  1. https://assets.codepen.io/16327/gsap-latest-beta.min.js
  2. https://assets.codepen.io/16327/Flip.min.js