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

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

              
                <main>
  <h1>Latest news, products, images, whatever!</h1>
  <ul class="gallery">
    <li class="card-wrapper">
      <article class="card">
        <div class="card__media">
          <img src="https://picsum.photos/300/300?random=1" alt="">
        </div>
        <div class="card__content">
          <h2 class="card__title">I am an item title</h2>
          <p class="card__description">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis corporis velit sequi accusantium, iure magnam a?
          </p>
        </div>
      </article>
    </li>
    <li class="card-wrapper">
      <article class="card">
        <div class="card__media">
          <img src="https://picsum.photos/300/300?random=2" alt="">
        </div>
        <div class="card__content">
          <h2 class="card__title">I am an item title</h2>
          <p class="card__description">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis corporis velit sequi accusantium, iure magnam a?
          </p>
        </div>
      </article>
    </li>
    <li class="card-wrapper">
      <article class="card">
        <div class="card__media">
          <img src="https://picsum.photos/300/300?random=3" alt="">
        </div>
        <div class="card__content">
          <h2 class="card__title">I am an item title</h2>
          <p class="card__description">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis corporis velit sequi accusantium, iure magnam a?
          </p>
        </div>
      </article>
    </li>
  </ul>
  <ul class="gallery">
    <li class="card-wrapper">
      <article class="card">
        <div class="card__media">
          <img src="https://picsum.photos/300/300?random=4" alt="">
        </div>
        <div class="card__content">
          <h2 class="card__title">I am an item title</h2>
          <p class="card__description">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis corporis velit sequi accusantium, iure magnam a?
          </p>
        </div>
      </article>
    </li>
    <li class="card-wrapper">
      <article class="card">
        <div class="card__media">
          <img src="https://picsum.photos/300/300?random=5" alt="">
        </div>
        <div class="card__content">
          <h2 class="card__title">I am an item title</h2>
          <p class="card__description">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis corporis velit sequi accusantium, iure magnam a?
          </p>
        </div>
      </article>
    </li>
    
  </ul>
  <div class="card-wrapper">
    <article class="card">
        <figure class="card__media">
          <img src="https://picsum.photos/300/300?random=6" alt="">
        </figure>
        <div class="card__content">
          <h2 class="card__title">Live, Laugh, Lobster</h2>
          <p class="card__description">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis corporis velit sequi accusantium, iure magnam a?
          </p>
        </div>
      </article>
  </div>
</main>
  
  
              
            
!

CSS

              
                /* Container query is initiated at line 44  */
/* Container queries start at line 87       */


@import url('https://fonts.googleapis.com/css2?family=Lato:[email protected];900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lobster&amp;display=swap');

:root {
  --bg-color: #f3edef;
  --color: #5c4924;
}

* {
  box-sizing: border-box;
}

body {
  background-color: var(--bg-color);
  color: var(--color);
  font-family: Lato, sans-serif;
	line-height: 1.4;
}

main {
  max-width: 80vw;
  margin: 0 auto 10rem;
}

img {
  width: 100%;
  display: block;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20ch, 1fr));  
  gap: 1rem;
  list-style-type: none;
  padding: 0;
  margin: 0 0 3rem 0;
}

.card-wrapper {
  container-type: inline-size; /* This is where I set the container type */
  
  /* This is just some styling */
  resize: horizontal;
  overflow: auto;
}

.card {
  background-color: #fff;
  background-image: 
    linear-gradient(
      -20deg, 
      rgba(201,199,202,1) 0%, 
      rgba(228,228,230,1) 20%, 
      rgba(250,250,250,1) 80%,       
      rgba(201,199,202,1) 100%);
  box-shadow: 0 0 20px hsl(0deg 0% 0% / 20%);  
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: 
    'media' 
    'content';
}

.card__media {
  grid-area: media;
  margin: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}


.card__media img {
  object-fit: cover;
}
  
 .card__content {
  grid-area: content;
  padding: 0 1rem 1rem;
}

/* Almost like media queries, but refering to the width of .card-wrapper on line 43 */
@container (min-width: 400px) {
  .card {
    grid-template-columns: 200px 1fr;
    grid-template-areas: 'media content';
    align-items: center;
  }
  
  .card__media {
    aspect-ratio: 1 / 1;
    margin: 1rem;
  }
}

@container (min-width: 900px) {
  .card {
    grid-template-columns: 1fr;
    font-size: 120%;
  }
  
  .card__media {
    aspect-ratio: 24 / 10;
    grid-row-start: 1;
    grid-column-start: 1;
    margin: 1rem;
  }
  .card__content {
    grid-row-start: 1;
    grid-column-start: 1;
    background-color: hsl(340deg 20% 94% / 80%);
    margin: 0 200px;
    padding: 50px;
  }
  .card__title {
    font-family: Lobster;
    font-size: 3rem;
    text-align: center;
    color: #ff00ff;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console