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 class="warning"><strong>Warning:</strong> Your browser does not support CSS container queries. Please open this demo in Chrome Canary with the experimental <i>#enable-container-queries</i> flag turned on.</div>

<!-- Button Component Start -->
<div class="cart-button-container">
  <button class="cart-button">
    <svg class="cart-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 173">
      <g class="plus-group">
        <line x1="278" y1="36" x2="278" y2="124" />
        <line x1="322" y1="80" x2="234" y2="80" />
      </g>
      <g class="cart-lines-group">
        <line x1="38" y1="68" x2="200" y2="68" />
        <line x1="83.54" y1="36.2" x2="95.69" y2="99.84" />
        <line x1="156.23" y1="36.2" x2="144.7" y2="99.84" />
      </g>
      <g class="cart-group">
        <polyline points="44 100 190.95 100 209.44 36 30.77 36 44.48 100" />
        <polyline points="185 131 51.44 131 44.78 99.91 24.46 5 0 5" />
        <circle cx="68" cy="152" r="16" />
        <circle cx="169" cy="152" r="16" />
      </g>
    </svg>
    <p class="cart-text"><span class="add">Add</span> <span class="to-cart">to cart</span></p>
  </button>
</div>
<!-- Button Component End -->

<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br>

<div class="product-card-container">
  <div class="product-card">
    <img src="https://www.ikea.com/us/en/images/products/graeddaepple-plant-pot-indoor-outdoor-pink-white__0952322_PE804311_S5.JPG?f=xs" />
    <div>
      <h3 class="title">Pink Hand-made Planter</h3>
      <span class="price">$16.99</span>
      <p class="desc">Handmade in Brooklyn, NY. Dimensions: 16" at opening, 10" at base. Round dome shape for single or multiple plantings. </p>
      <!-- Button Component Start -->
      <div class="cart-button-container">
        <button class="cart-button">
          <svg class="cart-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 173">
            <g class="plus-group">
              <line x1="278" y1="36" x2="278" y2="124" />
              <line x1="322" y1="80" x2="234" y2="80" />
            </g>
            <g class="cart-lines-group">
              <line x1="38" y1="68" x2="200" y2="68" />
              <line x1="83.54" y1="36.2" x2="95.69" y2="99.84" />
              <line x1="156.23" y1="36.2" x2="144.7" y2="99.84" />
            </g>
            <g class="cart-group">
              <polyline points="44 100 190.95 100 209.44 36 30.77 36 44.48 100" />
              <polyline points="185 131 51.44 131 44.78 99.91 24.46 5 0 5" />
              <circle cx="68" cy="152" r="16" />
              <circle cx="169" cy="152" r="16" />
            </g>
          </svg>
          <p class="cart-text"><span class="add">Add</span> <span class="to-cart">to cart</span></p>
        </button>
      </div>
      <!-- Button Component End -->
    </div>
  </div>
</div>
              
            
!

CSS

              
                :root {
  --btn-bg: #7fffd0;
  --btn-border: magenta;
  --text: black;
}

body {
  font-family: system-ui, Roboto;
  padding: 2rem;
}

// Set up the SVG
.plus-group > line {
  stroke-width: 20px;
  stroke: var(--text);
}

.cart-lines-group > line,
.cart-group > polyline,
.cart-group > circle {
  stroke-width: 10px;
  stroke: var(--text);
  fill: none;
}

// Style the button
.cart-button {
  background: var(--btn-bg);
  border: 2px dashed var(--btn-border);
  box-shadow: 6px 6px 0 var(--btn-border);
  max-width: 60px;
  display: inline-block;
  height: 3rem;
  border-radius: 10px;
}

.cart-text {
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-size: 18px;
  line-height: 0;
  padding: 0.25rem;
}

// Make up for "+" viewport spacing
.cart-icon {
  margin-right: -0.5rem;
}

// Mobile-first (smallest-up design)
.add-group,
.to-cart-group,
.plus-group,
.cart-lines-group,
.add,
.to-cart {
  display: none;
}

//  Enable containment on parent
.cart-button-container {
  container-type: inline-size;
  width: 100%;
}

.cart-icon {
  container-type: inline-size;
  width: 100%;
  height: 100%;
}

// Style children

// Cart lines at 30px or wider
@container (min-width: 30px) {
  .cart-lines-group {
    display: block;
  }
}

// Add "+" at 50px or wider
@container (min-width: 50px) {
  .plus-group {
    display: block;
  }
}

// "Add" instead of "+" at 100px
@container (min-width: 100px) {
  .cart-button {
    padding: 0 1rem;
    display: grid;
    max-width: 120px;
    grid-template-columns: 1fr 1fr;
  }

  .plus-group {
    display: none;
  }

  .cart-text .add {
    display: inline-block;
  }

  .cart-icon {
    margin-right: 0;
  }
}

// "Add to cart" for wider spaces
@container (min-width: 220px) {
  .cart-button {
    max-width: 260px;
    grid-template-columns: 1fr 3fr;
  }

  .cart-text .to-cart {
    display: inline-block;
  }
}

// Product Card
.product-card {
  padding: 1rem;
  border: 3px solid var(--btn-bg);
  text-align: center;
}

.product-card img {
  width: 100%;
  display: block;
  max-width: 200px;
  margin: 0 auto;
}

.product-card .desc {
  display: none;
}

.product-card .title {
  text-transform: uppercase;
  color: magenta;
  font-size: 1rem;
}

.product-card .price {
  display: block;
  margin: 1rem 0;
  line-height: 0;
  font-style: italic;
  color: #00b371;
}

// Product Card Responsive
.product-card-container {
  container-type: inline-size;
  container-name: product-card-container;
  width: 100%;
  max-width: 640px;
}

.product-card .cart-button {
  margin: 0 auto;
  container-name: product-card-container;
}

@container (min-width: 200px) {
  .product-card .desc {
    display: block;
  }

  .product-card {
    padding: 1rem 1rem 2rem;
    border: 5px solid var(--btn-bg);
    text-align: left;
  }

  .product-card .title {
    font-size: 1.25rem;
  }

  .product-card .price {
    font-size: 1rem;
  }
}

@container (min-width: 250px) {
  .product-card {
    border: 11px solid var(--btn-bg);
  }

  .product-card .title {
    font-size: 1.5rem;
  }

  .product-card .price {
    font-size: 1.25rem;
  }
}

@container product-card-container (min-width: 400px) {
  .product-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 2rem;
  }

  .product-card .cart-button {
    margin: 0;
  }
}

// Warning Bit
.warning {
  max-width: 460px;
  margin: 2rem auto;
  background: #ffcebf;
  border: 1px solid tomato;
  padding: 1rem;
}

@supports (container-type: inline-size) {
  .warning {
    display: none;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console