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

              
                <div id="app"></div>
<!-- The only anti-pattern I have cosciously left in the code is the passage of data from the slide component up to the top level of the view, but I reeeeeeally wanted to be able to change all those borders throughout the carousel at the same time so at least I did it in the cleanest way I know of. Please let me know if there are any other major flaws with this, as I can really really really use the feedback, cheers!-->
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Playfair+Display:ital@0;1&display=swap");

@keyframes fade-in {
  from {
    opacity: 0;
    transform: scale(1.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes next-slide-in {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes next-slide-out {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-100%);
  }
}

@keyframes back-slide-in {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes back-slide-out {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(100%);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;

  &::before,
  &::after {
    content: "";
  }
}

html {
  font-size: 10px;
}

#app {
  background: linear-gradient(to top left, #e66465, purple);
  //background: linear-gradient(to top left,#ff8a00,#e52e71);
  font-family: "Playfair Display", serif;
}

.wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  padding: 50px 50px 70px 50px;
  flex-direction: column;
  max-width: 650px;
  margin: 0 auto;

  @media only screen and (max-width: 650px) {
    padding: 30px 30px 50px 30px;
  }
}

.intro {
  text-align: center;
  font-size: 1.6rem;
  margin-bottom: 50px;
  //text-shadow: 0px 0px 10px purple;

  h1 {
    font-size: 5rem;
    font-weight: lighter;
  }

  h1,
  h2 {
    font-style: italic;
  }

  h2 {
    margin-bottom: 20px;
  }

  span {
    text-decoration: underline;
    color: #ff7a2a;
  }

  @media only screen and (max-width: 550px) {
    h1 {
      font-size: 4rem;
    }
    h2 {
      font-size: 1.6rem;
    }
  }

  @media only screen and (max-width: 450px) {
    p {
      font-size: 1.2rem;
    }
  }

  @media only screen and (max-width: 415px) {
    h1 {
      font-size: 3rem;
    }
  }
}

.carousel {
  display: flex;
  position: relative;
  overflow: hidden;
  justify-content: center;
  align-items: center;
  height: 350px;
  margin-bottom: 50px;
  box-shadow: 0px 15px 30px 0px #151515;
  border-style: solid;
  border-width: 3px;
  transition-duration: 0.5s;
  transition-property: border-color;

  .controls {
    position: absolute;
    z-index: 12121996; // <---- fun fact: this is my birthday
    height: 30px;
    width: 30px;
    background-color: purple;
    border-radius: 50%;
    cursor: pointer;
    color: white;
    font-size: 1.4rem;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    transition-duration: 0.1s;
    transition-timing-function: ease-in;

    &--back {
      left: 25px;

      span {
        position: relative;
        border-left: 5px solid pink;
        border-top: 5px solid transparent;
        border-right: 5px solid transparent;
        border-bottom: 5px solid pink;
        border-bottom-left-radius: 1px;
        transform: translate3d(-3px, -1px, 0) rotateZ(30deg);

        &::before {
          position: absolute;
          border-top: 4px solid pink;
          width: 12px;
          border-top-right-radius: 10px;
          height: 15px;
          transform: rotateZ(-45deg) translate3d(8px, -3px, 0);
        }
      }
    }

    &--next {
      right: 25px;

      span {
        position: relative;
        border-left: 5px solid transparent;
        border-top: 5px solid transparent;
        border-right: 5px solid pink;
        border-bottom: 5px solid pink;
        border-bottom-right-radius: 1px;
        transform: translate3d(4px, -1px, 0) rotateZ(-34deg);

        &::before {
          position: absolute;
          border-top: 4px solid pink;
          width: 12px;
          border-top-left-radius: 10px;
          height: 15px;
          transform: rotateZ(45deg) translate3d(-17px, 5px, 0);
        }
      }
    }

    &:hover {
      height: 33px;
      width: 33px;
    }
  }

  & .slide {
    position: absolute;
    background-color: pink;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    padding: 50px;
    z-index: 0;

    &__copy-message {
      position: absolute;
      top: 10px;
      font-size: 1.2rem;
      transition-duration: 0.5s;

      &.nope {
        top: 0;
        transform: translate3d(0, -100%, 0);
      }
    }

    &__shape {
      animation-name: fade-in;
      animation-duration: 0.5s;
      animation-fill-mode: forwards;
      cursor: crosshair;
      position: relative;

      &--heart {
        position: relative;
        width: 100px;
        height: 90px;

        &::before,
        &::after {
          position: absolute;
          left: 50px;
          top: 0;
          width: 50px;
          height: 80px;
          background: red;
          border-radius: 50px 50px 0 0;
          transform: rotate(-45deg);
          transform-origin: 0 100%;
        }

        &::after {
          left: 0;
          transform: rotate(45deg);
          transform-origin: 100% 100%;
        }
      }

      &--pacman {
        width: 0px;
        height: 0px;
        border-right: 60px solid transparent;
        border-top: 60px solid orange;
        border-left: 60px solid orange;
        border-bottom: 60px solid orange;
        border-top-left-radius: 60px;
        border-top-right-radius: 60px;
        border-bottom-left-radius: 60px;
        border-bottom-right-radius: 60px;
      }

      &--yin-yang {
        width: 96px;
        box-sizing: content-box;
        height: 48px;
        background: #eee;
        border-color: black;
        border-style: solid;
        border-width: 2px 2px 50px 2px;
        border-radius: 100%;
        position: relative;

        &::before {
          position: absolute;
          top: 50%;
          left: 0;
          background: #eee;
          border: 18px solid black;
          border-radius: 100%;
          width: 12px;
          height: 12px;
          box-sizing: content-box;
        }

        &::after {
          position: absolute;
          top: 50%;
          left: 50%;
          background: black;
          border: 18px solid #eee;
          border-radius: 100%;
          width: 12px;
          height: 12px;
          box-sizing: content-box;
        }
      }

      &--cut-diamond {
        border-style: solid;
        border-color: transparent transparent DodgerBlue transparent;
        border-width: 0 25px 25px 25px;
        height: 0;
        width: 50px;
        box-sizing: content-box;
        position: relative;
        margin-bottom: 50px;

        &:after {
          position: absolute;
          top: 25px;
          left: -25px;
          width: 0;
          height: 0;
          border-style: solid;
          border-color: DodgerBlue transparent transparent transparent;
          border-width: 70px 50px 0 50px;
        }
      }

      &--infinity {
        position: relative;
        width: 150px;
        height: 80px;
        box-sizing: content-box;

        &::before,
        &::after {
          content: "";
          box-sizing: content-box;
          position: absolute;
          top: 0;
          left: 0;
          width: 40px;
          height: 40px;
          border: 15px solid green;
          border-radius: 40px 40px 0 40px;
          transform: rotate(-45deg);
        }

        &::after {
          left: auto;
          right: 0;
          border-radius: 40px 40px 40px 0;
          transform: rotate(45deg);
        }
      }
    }
  }

  &--heart {
    border-color: red;
  }

  &--pacman {
    border-color: orange;
  }

  &--yin-yang {
    border-color: black;
  }

  &--cut-diamond {
    border-color: DodgerBlue;
  }

  &--infinity {
    border-color: green;
  }

  @media only screen and (max-width: 450px) {
    height: 300px;
  }
}

.code-wrapper {
  border-width: 3px;
  border-style: solid;
  background-color: pink;
  box-shadow: 0px 15px 30px 0px #151515;
  position: relative;
  overflow: hidden;
  width: 100%;
  display: flex;
  transition-property: border-color;
  transition-duration: 0.5s;

  .code {
    font-family: monospace;
    font-size: 1.2rem;
    white-space: pre-wrap;
    animation-duration: 1s;
    animation-fill-mode: forwards;
    padding: 60px;
    width: 100%;

    &--last {
      position: absolute;

      &.slide-left {
        animation-name: back-slide-out;
      }

      &.slide-right {
        animation-name: next-slide-out;
      }
    }

    &--active {
      position: relative;

      &.slide-left {
        animation-name: back-slide-in;
      }

      &.slide-right {
        animation-name: next-slide-in;
      }
    }

    @media only screen and (max-width: 550px) {
      padding: 45px;
    }

    @media only screen and (max-width: 450px) {
      padding: 30px;
    }
  }

  &--heart {
    border-color: red;
  }

  &--pacman {
    border-color: orange;
  }

  &--yin-yang {
    border-color: black;
  }

  &--cut-diamond {
    border-color: DodgerBlue;
  }

  &--infinity {
    border-color: green;
  }
}

              
            
!

JS

              
                !(function () {
  const useState = React.useState;

  const SHAPES = [
    [
      "heart",
      `#heart {

  position: relative;
  width: 100px;
  height: 90px;

}

#heart::before, #heart::after {

  content: '';
  position: absolute;
  left: 50px;
  top: 0;
  width: 50px;
  height: 80px;
  background: red;
  border-radius: 50px 50px 0 0;
  transform: rotate(-45deg);
  transform-origin: 0 100%;

}

#heart::after {

  left: 0;
  transform: rotate(45deg);
  transform-origin: 100% 100%;

}`
    ],
    [
      "pacman",
      `#pacman {

  width: 0px;
  height: 0px;
  border-right: 60px solid transparent;
  border-top: 60px solid orange;
  border-left: 60px solid orange;
  border-bottom: 60px solid orange;
  border-top-left-radius: 60px;
  border-top-right-radius: 60px;
  border-bottom-left-radius: 60px;
  border-bottom-right-radius: 60px;

}`
    ],
    [
      "yin-yang",
      `#yin-yang {

  width: 96px;
  box-sizing: content-box;
  height: 48px;
  background: white;
  border-color: black;
  border-style: solid;
  border-width: 2px 2px 50px 2px;
  border-radius: 100%;
  position: relative;

}

#yin-yang::before {

  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  background: white;
  border: 18px solid black;
  border-radius: 100%;
  width: 12px;
  height: 12px;
  box-sizing: content-box;

}

#yin-yang::after {

  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  background: black;
  border: 18px solid white;
  border-radius: 100%;
  width: 12px;
  height: 12px;
  box-sizing: content-box;

}`
    ],
    [
      "cut-diamond",
      `#cut-diamond {

  border-style: solid;
  border-color: transparent transparent DodgerBlue transparent;
  border-width: 0 25px 25px 25px;
  height: 0;
  width: 50px;
  box-sizing: content-box;
  position: relative;
  margin-bottom: 50px;

}

#cut-diamond::after {

  content: "";
  position: absolute;
  top: 25px;
  left: -25px;
  width: 0;
  height: 0;
  border-style: solid;
  border-color: DodgerBlue transparent transparent transparent;
  border-width: 70px 50px 0 50px;

}`
    ],
    [
      "infinity",
      `#infinity {

  position: relative;
  width: 150px;
  height: 80px;
  box-sizing: content-box;

}

#infinity::before, #infinity::after {

  content: "";
  box-sizing: content-box;
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  border: 15px solid green;
  border-radius: 40px 40px 0 40px;
  transform: rotate(-45deg);

}

#infinity::after {

  left: auto;
  right: 0;
  border-radius: 40px 40px 40px 0;
  transform: rotate(45deg);

}`
    ]
  ];

  function App(props) {
    const [app, updateApp] = useState({
      currentIndex: 0,
      lastIndex: -1,
      direction: 0
    });

    return (
      <div className="wrapper">
        <div className="intro">
          <h1>“The Shapes of CSS”</h1>
          <h2>from CSS-Tricks</h2>
          <p>
            an incredibly clever article written by <span>Chris Coyier</span>,
          </p>
          <p>shamelessly copied (only a little part) by me</p>
        </div>

        <Carousel
          direction={app.direction}
          currentIndex={app.currentIndex}
          lastIndex={app.currentIndex}
          updateApp={updateApp}
          shapes={props.shapes}
        />

        <Code
          direction={app.direction}
          lastShape={props.shapes[app.lastIndex]}
          currentShape={props.shapes[app.currentIndex]}
          shapes={props.shapes}
        />
      </div>
    );
  }

  function Carousel(props) {
    function showNext(index) {
      let lastIndex =
        index < 0
          ? 0
          : index === props.shapes.length
          ? props.shapes.length - 1
          : index;
      let currentIndex = index + 1 === props.shapes.length ? 0 : index + 1;
      props.updateApp({ currentIndex, lastIndex, direction: 1 });
    }

    function showPrevious(index) {
      let lastIndex = index < 0 ? 0 : index;
      let currentIndex = index - 1 < 0 ? props.shapes.length - 1 : index - 1;
      props.updateApp({ currentIndex, lastIndex, direction: -1 });
    }

    return (
      <div
        className={"carousel carousel--" + props.shapes[props.currentIndex][0]}
      >
        <div
          onClick={() => showPrevious(props.currentIndex)}
          className="controls controls--back"
        >
          <span></span>
        </div>

        <Slide shape={props.shapes[props.currentIndex]} />

        <div
          onClick={() => showNext(props.currentIndex)}
          className="controls controls--next"
        >
          <span></span>
        </div>
      </div>
    );
  }

  function Slide(props) {
    const [copyMessage, setCopyMessage] = useState(false);

    function copyCSS(shapeCSS) {
      navigator.clipboard.writeText(shapeCSS).then(
        () => {
          console.log("Successfully copied CSS to clipboard");

          setCopyMessage(true);

          setTimeout(setCopyMessage, 2000, false);
        },
        () => {
          console.log("Error: couldn't copy to clipboard :(");
        }
      );
    }

    return (
      <div key={props.shape[0]} className={"slide slide--" + props.shape[0]}>
        <h6
          className={"slide__copy-message " + (copyMessage ? "show" : "nope")}
        >
          I am in your Clipboard!
        </h6>

        <div
          onClick={() => copyCSS(props.shape[1])}
          className={"slide__shape slide__shape--" + props.shape[0]}
        ></div>
      </div>
    );
  }

  function Code(props) {
    return (
      <div className={"code-wrapper code-wrapper--" + props.currentShape[0]}>
        <pre
          key={props.currentShape[0]}
          className={
            "code code--active" +
            (props.direction < 0 ? " slide-left" : " slide-right")
          }
        >
          {props.currentShape[1]}
        </pre>

        {props.lastShape && (
          <pre
            key={props.lastShape[0]}
            className={
              "code code--last" +
              (props.direction < 0 ? " slide-left" : " slide-right")
            }
          >
            {props.lastShape[1]}
          </pre>
        )}
      </div>
    );
  }

  ReactDOM.render(<App shapes={SHAPES} />, document.getElementById("app"));
})();

              
            
!
999px

Console