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="card__container">
  <div class="card">
    <img src="https://picsum.photos/2568/600" width="2568" height="600" alt="" class="card__thumbnail" />
    <h3 class="card__title">Container Queries Rule</h3>
    <p class="card__describe">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quis magni eveniet natus nulla distinctio eaque?</p>
    <button class="card__button">Order now</button>
  </div>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

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

body {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  padding: 20px;

  display: grid;
  gap: 20px;
  align-items: start;
  justify-content: center;
}

.card__container {
  overflow: hidden;
  resize: horizontal;
  min-inline-size: 280px;
  max-inline-size: calc(100vw - 40px);
}

.card {
  display: grid;
  gap: 1rem;
  margin: 5vh auto;
  border-radius: 0.5rem;
  box-shadow: 0 0.25rem 0.5rem -0.15rem hsla(0 0% 0% / 55%);
  background-color: #fff;
}

.card__thumbnail {
  max-width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  object-fit: cover;
  border-radius: 0.5rem 0.5rem 0 0;
}

.card__title {
  font-weight: 700;
  font-size: clamp(1.2rem, 1.2rem + 3vw, 1.5rem);
  padding: 0 20px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.card__describe {
  color: #666;
  line-height: 1.4;
  padding: 0 20px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.card__button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border: none;
  border-radius: 10rem;
  background-color: #feca53;
  padding: 10px 20px;
  color: #000;
  text-decoration: none;
  box-shadow: 0 3px 8px rgb(0 0 0 / 7%);
  transition: all 0.2s linear;
  font-weight: 700;
  justify-self: end;
  margin: 0 20px 20px 0;
  cursor: pointer;
}

.card__button:hover {
  background-color: #ff9800;
}

/* Defining containment */
.card__container {
  container-type: inline-size;
}

/* The card container width is greater than or equal to 400px */

@container (width >= 400px) {
  .card {
    grid-template-columns: 180px 1fr;
    grid-template-areas:
      "thumbnail title"
      "thumbnail describe"
      "thumbnail button";
    gap: 10px 20px;
    align-items: start;
  }

  .card__thumbnail {
    grid-area: thumbnail;
    aspect-ratio: 1;
    border-radius: 0.5rem 0 0 0.5rem;
  }

  .card__title {
    grid-area: title;
    padding-left: 0;
    margin-top: 16px;
  }

  .card__describe {
    grid-area: describe;
    padding-left: 0;
    -webkit-line-clamp: 2;
  }

  .card__button {
    grid-area: button;
  }
}

/* The card container width is greater than or equal to 550px */
@container (width >= 550px) {
  .card {
    grid-template-columns: 240px 1fr;
    grid-template-rows: 56px auto 60px;
  }

  .card__describe {
    -webkit-line-clamp: 3;
  }
}

/* The card container width is greater than or equal to 550px */
@container (width >= 700px) {
  .card {
    grid-template-areas:
      "thumbnail"
      "title"
      "describe";
    grid-template-columns: auto;
    grid-template-rows: auto auto auto;
    gap: 1rem;
  }

  .card::before {
    content: "";
    background-color: rgb(0 0 0 / 0.4);
    background-image: linear-gradient(
      to top,
      rgb(0 0 0 / 0.8),
      rgb(0 0 0 / 0) 60%,
      rgb(0 0 0 /0.8) 100%
    );
    display: block;
    grid-row: 1 / -1;
    grid-column: 1 / -1;
    z-index: 2;
    min-height: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 0.5rem;
  }

  .card__thumbnail {
    grid-row: 1 / -1;
    aspect-ratio: 4 / 3;
    border-radius: 0.5rem;
    z-index: 1;
  }

  .card__title {
    padding: 0 20px;
    z-index: 3;
    color: #fff;
  }

  .card__describe {
    -webkit-line-clamp: 2;
    padding: 0 20px;
    margin-bottom: 20px;
    z-index: 3;
    color: #ddd;
  }

  .card__button {
    display: none;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console