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="layout">

  <div class="layout__item" style="--featured-2: true; width: 670px;">
    <article class="post">
      <div class="test">
        <div class="category">Government & Policy</div>
        <h3 class="title">Worldcoin hopes to resume iris scans in Kenya</h3>
        <div class="meta">
          <p>Ahmad Shadeed</p>
          <time class="river-byline__full-date-time" datetime="2023-08-03T14:20:14">5:20 PM GMT+3<span class="full-date-time__separator">•</span>August 3, 2023</time>
        </div>
      </div>

      <div class="desc">
        Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
      </div>

      <figure class="media">
        <img alt="" src="https://techcrunch.com/wp-content/uploads/2023/03/reddit.jpg?w=850&h=492&crop=1">
      </figure>
    </article>
  </div>

  <div class="layout__item" style="--type: plain; width: 400px;">
    <article class="post">
      <div class="test">
        <div class="category">Government & Policy</div>
        <h3 class="title">Worldcoin hopes to resume iris scans in Kenya</h3>
        <div class="meta">
          <p>Ahmad Shadeed</p>
          <time class="river-byline__full-date-time" datetime="2023-08-03T14:20:14">5:20 PM GMT+3<span class="full-date-time__separator">•</span>August 3, 2023</time>
        </div>
      </div>

      <div class="desc">
        Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
      </div>

      <figure class="media">
        <img alt="" src="https://techcrunch.com/wp-content/uploads/2023/03/reddit.jpg?w=850&h=492&crop=1">
      </figure>
    </article>
  </div>

  <div class="layout__item" style="--thumb: true;">
    <article class="post">
      <div class="test">
        <div class="category">Government & Policy</div>
        <h3 class="title">Worldcoin hopes to resume iris scans in Kenya</h3>
        <div class="meta">
          <p>Ahmad Shadeed</p>
          <time class="river-byline__full-date-time" datetime="2023-08-03T14:20:14">5:20 PM GMT+3<span class="full-date-time__separator">•</span>August 3, 2023</time>
        </div>
      </div>

      <div class="desc">
        Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
      </div>

      <figure class="media">
        <img alt="" src="https://techcrunch.com/wp-content/uploads/2023/03/reddit.jpg?w=850&h=492&crop=1">
      </figure>
    </article>
  </div>

  <div class="layout__item" style="--flipped: true;">
    <article class="post">
      <div class="test">
        <div class="category">Government &amp; Policy</div>
        <h3 class="title">Worldcoin hopes to resume iris scans in Kenya</h3>
        <div class="desc desc-test">
          Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
        </div>
        <div class="meta">
          <p>Ahmad Shadeed</p>
          <time class="river-byline__full-date-time" datetime="2023-08-03T14:20:14">5:20 PM GMT+3<span class="full-date-time__separator">•</span>August 3, 2023</time>
        </div>
      </div>

      <div class="desc">
        Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
      </div>

      <figure class="media">
        <img alt="" src="https://techcrunch.com/wp-content/uploads/2023/03/reddit.jpg?w=850&amp;h=492&amp;crop=1">
      </figure>
    </article>
  </div>

  <div class="layout__item">
    <article class="post">
      <div class="test">
        <div class="category">Government &amp; Policy</div>
        <h3 class="title">Worldcoin hopes to resume iris scans in Kenya</h3>
        <div class="meta">
          <p>Ahmad Shadeed</p>
          <time class="river-byline__full-date-time" datetime="2023-08-03T14:20:14">5:20 PM GMT+3<span class="full-date-time__separator">•</span>August 3, 2023</time>
        </div>
      </div>

      <div class="desc">
        Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
      </div>
    </article>
  </div>

  <div class="layout__item" style="--featured-1: true;">
    <article class="post">
      <div class="test">
        <h3 class="title">Worldcoin hopes to resume iris scans in Kenya</h3>
        <div class="desc desc-test">
          Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
        </div>
        <div class="meta">
          <p>Ahmad Shadeed</p>
          <time class="river-byline__full-date-time" datetime="2023-08-03T14:20:14">5:20 PM GMT+3<span class="full-date-time__separator">•</span>August 3, 2023</time>
        </div>
      </div>

      <div class="desc">
        Sam Altman’s crypto startup Worldcoin yesterday faced its first major hurdle in Africa when authorities in Kenya suspended
      </div>

      <figure class="media">
        <img alt="" src="https://techcrunch.com/wp-content/uploads/2023/03/reddit.jpg?w=850&amp;h=492&amp;crop=1">
      </figure>
    </article>
  </div>

</div>
              
            
!

CSS

              
                .layout {
  --cols: 1fr;
  display: grid;
  grid-template-columns: var(--cols);
  align-items: start;
  gap: 4rem;
  max-width: 1200px;
  margin: 1rem auto;
}

.layout__item {
  container-name: test;
  container-type: inline-size;
  resize: horizontal;
  overflow: hidden;
  width: 100%;
  max-width: 90vw;
  background-color: #f4f4f4;
  padding: 1rem;
  border-radius: 12px;
}

.feature-island {
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: max(1rem, 1rem + 2cqw);

  @container test (min-width: 600px) {
    grid-template-columns: 2fr 1.25fr;
  }
}

/* Post */
.post {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;

  @container (min-width: 450px) {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.title {
  font-weight: 800;
  font-size: max(1rem, 2.5cqw);
  line-height: 1;
  grid-column: 1/2;

  @container style(--thumb: true) {
    font-size: max(1.25rem, 3cqw);
  }
}

.meta {
  grid-column: 1/2;

  p:first-child {
    font-weight: 500;
    font-size: 14px;
  }
}

.desc {
  color: #777;

  @container style(--thumb: true) {
    grid-column: 2/3;
    grid-row: 1/-1;

    display: none;
    font-size: clamp(14px, 1.5cqw, 20px);

    @container (min-width: 450px) {
      display: block;
    }
  }
}

.media {
  position: relative;
  height: fit-content;

  &:after {
    content: "";
    position: absolute;
    inset: 0;
    background: lightgrey;
  }
  @container (min-width: 450px) {
    grid-row: 1/-1;
    grid-column: 3/4;
  }
}

.category {
  color: #00d301;
  font-size: 14px;
}

/********** Plain **********/
.test {
  display: flex;
  flex-direction: column;
  gap: max(2px, 0.5cqw);
}

@container style(--type: plain) {
  .post {
    display: block;
  }

  .desc,
  time {
    display: none;
  }

  .title {
    font-size: max(1rem, 3.5cqw);
  }

  .media {
    display: none;
  }
}

@container style(--featured-2: true) {
  .title {
    font-size: min(45px, 6cqw);
  }

  .desc {
    font-size: max(1rem, 3cqw);
  }

  .category,
  time {
    display: none;
  }

  .post {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 0.5rem;
  }

  .media,
  .desc {
    grid-area: initial;
  }

  .meta {
    order: 2;
  }

  .media {
    order: 4;
  }

  .test {
    display: contents;
  }
}

.post:not(:has(.media)) {
  grid-template-columns: 1fr;

  .desc {
    display: none;
  }

  @container (min-width: 450px) {
    grid-template-columns: 1fr 1fr 1fr;

    .desc {
      display: block;
      grid-column: 2/4;
    }
  }
}

.desc-test {
  display: none;
}

@container style(--flipped: true) {
  .post {
    grid-template-columns: minmax(min(120px, 10cqw), min(270px, 27cqw)) 1fr;
    row-gap: 0;
  }

  .test {
    grid-column: 2/3;
    grid-row: 1;
  }

  .desc {
    grid-row: 2;
    display: none;
  }

  .media {
    grid-column: 1;
  }

  .desc-test {
    display: block;
  }
}

@container style(--featured-1: true) {
  .post {
    display: flex;
    flex-direction: column;
    column-gap: 0.5rem;
  }

  .test {
    &:before {
      content: "Featured article";
      display: block;
      font-size: 1.5rem;
      font-weight: bold;
      background: linear-gradient(32deg, #00d301 0%, #36c275 50%, #00a562 100%);
      background-clip: text;
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }

  .desc {
    display: none;
  }

  .desc-test {
    display: block;
  }

  @container (min-width: 600px) {
    .test {
      grid-column: 1/2;
      grid-row: 1;
    }

    .media {
      grid-column: 2/-1;
    }

    .post {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      column-gap: 2rem;
      row-gap: 0;
    }
  }
}

.other-content {
  padding-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* other styles */

body {
  font-family: system-ui;
  line-height: 1.45;
  padding: 1rem;
}

* {
  box-sizing: border-box;
}

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

              
            
!

JS

              
                // // Function to update the element with its width value
// function updateElementWidth(elementClass) {
//   const elements = document.getElementsByClassName(elementClass);
//   for (let i = 0; i < elements.length; i++) {
//     const element = elements[i];
//     element.innerHTML = `${elementClass} width: ${element.offsetWidth}px`;
//   }
// }

// // Function to handle window resize event
// function handleWindowResize() {
//   updateElementWidth("header");
//   updateElementWidth("content");
//   updateElementWidth("aside");
//   updateElementWidth("footer");
// }

// // Add event listener to handle window resize
// window.addEventListener("resize", handleWindowResize);

// // Initial call to update the element widths when the page loads
// handleWindowResize();

              
            
!
999px

Console