Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <!-- BOOK TEMPLATE -->
<template id="book-template">
  <style>
    /* Layout Container */
    :host {
      display: block;
      contain: layout style inline-size;
      perspective:1000px;
      cursor: grab;
    }
    
    /* Base Styles */
    ::slotted(img) {
      display:block;
      width:100%;
      height: auto;
      border-radius: 0px 2px 2px 0px;
      background-color: var(--cover-color);
    }
    .book {
      font-size: var(--font-size, 1rem);
      font-weight: 400;
    }
    .meta {
      padding-top: 1em;
      line-height: 1.3;
    }
    .title {
      font-size: 1.25em;
      font-family: "Merriweather", serif;
      margin:0 0 .5rem 0;
    }
    .author {
      font-size: .875em;
      font-family: sans-serif;
      margin:0;
    }
    
    /* Small Variant */
    @container (max-width: 200px) {
      .book {
        --font-size: .5rem;
      }
      .author {
        display: none;
      }
    }
    
    /* Medium Variant */
    @container (min-width: 201px) and (max-width: 399px) {
      .book {
        --font-size: 1rem;
        display: grid;
        align-items: start;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
      }
    }
    
    /* Large Variant */
    @container (min-width: 400px) {
      ::slotted(img) {
        transform: translateZ(40px);
        box-shadow: 5px 5px 20px rgba(0,0,0,0.1);
      }
      .book {
        --font-size: 1.5rem;
        padding:1rem;
      }
      .front {
        position: relative;
        transform-style: preserve-3d;
        transform: rotateY(-25deg);
        transition: transform .5s ease;
      }
      .front::before {
        position: absolute;
        content: ' ';
        left: 100%;
        top: 1%;
        width: 80px;
        height: 98%;
        transform: translate(-55%,0) rotateY(
    90deg
    );
        background: linear-gradient(
    90deg
    , #fff 0%, #f9f9f9 5%, #fff 10%, #f9f9f9 15%, #fff 20%, #f9f9f9 25%, #fff 30%, #f9f9f9 35%, #fff 40%, #f9f9f9 45%, #fff 50%, #f9f9f9 55%, #fff 60%, #f9f9f9 65%, #fff 70%, #f9f9f9 75%, #fff 80%, #f9f9f9 85%, #fff 90%, #f9f9f9 95%, #fff 100% );
      }
      .front::after {
        position: absolute;
        top: 0;
        left: 1%;
        content: ' ';
        width: 100%;
        height: 100%;
        transform: translateZ(-40px);
        background-color: var(--cover-color, #000);
        border-radius: 0 2px 2px 0;
        box-shadow: -10px 0 50px 10px rgba(0,0,0,0.3);
      }
    }
  </style>
  <article class="book">
    <div class="front">
      <slot name="cover"></slot>
    </div>
    <div class="meta">
      <h2 class="title"><slot name="title"></slot></h2>
      <p class="author"><slot name="author"></slot></p>
    </div>
  </article>
</template>
<!-- END BOOK TEMPLATE -->



<div class="layout">
  <!-- HEADER -->
  <header class="header">
    <h1 class="logo">CQ Bookstore</h1>
    <p class="by">by <a href="https://mxb.dev">MXB</a></p>
  </header>

  <!-- FEATURED STAGE -->
  <div class="stage js-drag-container">
    <h2 class="capitals">Featured</h2>
    
      <book-element color="#52947c">
        <img slot="cover" src="https://assets.codepen.io/1256430/oz.avif" alt="" />
        <span slot="title">The Wizard of Oz</span>
        <span slot="author">L. Frank Baum</span>
      </book-element>

  </div>

  <!-- MAIN CONTENT AREA -->
  <main class="content">
    <h2 class="capitals">Bestsellers</h2>

    <div class="support-notice">
      ⚠️ Your browser does not support Container Queries - Enable them in Chrome Canary at chrome://flags to see this demo.
    </div>

    <div class="booklist js-drag-container">
      
      <book-element color="#BA423D">
        <img slot="cover" src="https://assets.codepen.io/1256430/1984.avif" alt="" />
        <span slot="title">1984</span>
        <span slot="author">George Orwell</span>
      </book-element>

      <book-element color="#d2d5dc">
        <img slot="cover" src="https://assets.codepen.io/1256430/little-women.avif" alt="" />
        <span slot="title">Little Women</span>
        <span slot="author">Louisa May Alcott</span>
      </book-element>

      <book-element color="#fefef2">
        <img slot="cover" src="https://assets.codepen.io/1256430/fahrenheit-451.avif" alt="" />
        <span slot="title">Fahrenheit 451</span>
        <span slot="author">Ray Bradbury</span>
      </book-element>
      
      <book-element color="#0c0d12">
        <img slot="cover" src="https://assets.codepen.io/1256430/moby-dick.avif" alt="" />
        <span slot="title">Moby Dick</span>
        <span slot="author">Herman Melville</span>
      </book-element>
      
      <book-element color="#1480a8"> 
        <img slot="cover" src="https://assets.codepen.io/1256430/pride.avif" alt="" />
        <span slot="title">Pride and Prejudice</span>
        <span slot="author">Jane Austen</span>
      </book-element>
      
      <book-element color="#cb0f2d">
        <img slot="cover" src="https://assets.codepen.io/1256430/sputnik-sweetheart.avif" alt="" />
        <span slot="title">Sputnik Sweetheart</span>
        <span slot="author">Haruki Murakami</span>
      </book-element>

    </div>
  </main>


  <!-- SHOPPING CART -->
  <div class="cart js-drag-container">
    <h2 class="capitals">Cart</h2>
    
    <book-element color="#067682">
      <img slot="cover" src="https://assets.codepen.io/1256430/don-quixote.avif" alt="" />
      <span slot="title">Don Quixote</span>
      <span slot="author">Miguel de Cervantes</span>
    </book-element>

  </div>
</div>

<!-- INCLUDE DRAGULA.JS -->
<script src="https://unpkg.com/dragula@3.7.2/dist/dragula.min.js"></script>
              
            
!

CSS

              
                :root {
  --spacing: 1rem;
  --highlight-color: #52947c;
}

body {
  font-family: sans-serif;
}

/* Basic Layout Sections */

.layout {
  min-height: 100vh;
}

.header {
  display:flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
  padding: 0 var(--spacing);
  box-shadow:0 2px 16px rgba(0,0,0,0.1);
  position:relative;
  z-index: 1;
}

.stage,
.content,
.cart {
  padding: var(--spacing);
  overflow-y: auto;
}

.stage {
  position:relative;
}
.stage::after {
  content: "";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  background-color: var(--bg-color, var(--highlight-color));
  filter: brightness(1.5);
  transition: background-color .5s linear;
  opacity:0.25;
}

.booklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(201px, 1fr));
  gap: var(--spacing);
}

.cart {
  background-color: #f5f3f3;
}
.cart > * + * {
  margin-top: 1rem;
}

/* Desktop Layout */

@media (min-width: 1260px) {
  .layout {
    --spacing: 2rem;
    
    display:grid;
    height: 100vh;
    grid-template-rows: 3.5rem auto;
    grid-template-columns: 480px 1fr 130px;
    overflow-y: hidden;
  }
  .header {
    grid-column: 1 / -1;
  }
}

/* No-CQ Support Notice */

.support-notice {
  padding: 1rem;
  border-radius: .25rem;
  margin-bottom: var(--spacing);
  border: 2px solid salmon;
  background-color: rgba(salmon, .1);
  line-height: 1.4;
}

@supports (contain: layout inline-size) {
	.support-notice {
		display: none;
	}
}

/* Misc Helper Classes */

.gu-mirror {
  width: 180px !important;
}

.capitals {
  font-size: .75rem;
  font-weight: bold;
  letter-spacing:.25em;
  text-transform: uppercase;
  margin-bottom: var(--spacing);
}

.logo {
  font-family: "Merriweather", serif;
}

.by a {
  color: inherit;
  text-decoration:underline;
}
              
            
!

JS

              
                // Init Dragula
if (dragula) {
  const drg = dragula(Array.from(document.querySelectorAll('.js-drag-container')))
  drg.on('drop', (el, target, source, sibling) => {
    if (target.classList.contains('stage')) {
      const color = el.getAttribute('color')
      target.style.setProperty('--bg-color', color)
      
      if (sibling && sibling.tagName.toLowerCase() === 'book-element') {
        source.appendChild(sibling)
      }
    }
  })
}

// Custom Element Definition
class BookElement extends HTMLElement {
  constructor() {
    super()
    this.template = document.getElementById('book-template')
    
    if (this.template) {
      this.attachShadow({ mode: "open" }).appendChild(this.template.content.cloneNode(true))
    }
  }
  
  static get observedAttributes() {
    return ['color'];
  }
  
  attributeChangedCallback(attrName, oldValue, newValue) {
    if (newValue !== oldValue) {
      this[attrName] = this.getAttribute(attrName);
      this.update();
    }
  }
  
  connectedCallback() {
    this.update();
  }
  
  update() {
    if (this.color) {
      this.style.setProperty('--cover-color', this.color)
    }
  }
}

if ('customElements' in window) {
    customElements.define('book-element', BookElement)
}
              
            
!
999px

Console