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">
  <header class="header item">
    <nav>
      <p>Nav element</p>
    </nav>
  </header>

  <main class="main-container" style="padding: 0;">
    <div class="content feature-island">
      <div class="feature-island-main" style="--featured-2: 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="feature-island-posts" style="--type: plain;">
        <div class="post-wrapper">
          <article class="post">
            <div class="test">
              <div class="category">Government & Policy</div>
              <h3 class="title">This $70 device can spoof an Apple device and trick you into sharing your password</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="post-wrapper">
          <article class="post">
            <div class="test">
              <div class="category">Government & Policy</div>
              <h3 class="title">Snapchat’s My AI goes rogue, posts to Stories, but Snap confirms it was just a glitch</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="post-wrapper">
          <article class="post">
            <div class="test">
              <div class="category">Government & Policy</div>
              <h3 class="title">Women-led firms are a bright spot in 2023’s fundraising slump</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="post-wrapper">
          <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>

          </article>
        </div>
      </div>
    </div>

    <div class="other-content" style="container-type: inline-size; --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>

      <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 style="--flipped: 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="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&h=492&crop=1">
          </figure>
      </div>
      </article>
      <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>
      </article>

    </div>
  </main>
  <aside class="item aside">
    <p>Ads and side stuff</p>
  </aside>

  <footer class="item footer">
    <p>I'm the footer</p>
  </footer>
</div>
              
            
!

CSS

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

  @media (min-width: 720px) {
    --cols: 5fr 300px;
  }

  @media (min-width: 1020px) {
    --cols: minmax(min(160px, 10vw), min(200px, 15vw))
      minmax(min(1200px, 0px), min(1390px, 100%))
      minmax(min(200px, 10vw), min(300px, 15vw));
  }
}

header {
  position: sticky;
  top: 0;
  grid-column: 1 / -1;
  //display: none;
  opacity: 0;

  @media (min-width: 1020px) {
    grid-column: 1 / 2;
  }
}

footer {
  grid-column: 1 / -1;

  @media (min-width: 1020px) {
    grid-column: 2 / -1;
  }
}

.aside {
  display: none;
  @media (min-width: 720px) {
    display: block;
  }
}

.item {
  padding: 2rem;
  font-size: 1rem;
  background-color: lightgrey;
  text-align: center;
}

.wrapper {
  max-width: 850px;
  margin: 1rem auto;
  padding-block: 1rem;

  > * + * {
    margin-top: 2rem;
  }
}

/* Feature island */
.main-container {
  container-name: test;
  container-type: inline-size;
}

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

  > * {
    //outline: solid 1px red;
  }

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

.feature-island-main {
  container-name: main;
  container-type: inline-size;
}

.feature-island-posts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

  @container (min-width: 450px) {
    grid-template-columns: 1fr 1fr 1fr;
    //grid-template-rows: max-content max-content 50px;
  }
}

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

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

.meta {
  grid-column: 1/2;

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

.desc {
  grid-column: 2/3;
  grid-row: 1/-1;
  color: #777;

  @container style(--thumb: true) {
    display: none;
    font-size: clamp(14px, 1.5cqw, 20px);

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

.media {
  @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;
  }
  // .post {
  //   display: flex;
  //   flex-direction: column;
  //   gap: 0.35rem;
  // }

  .desc,
  time {
    display: none;
  }

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

  // .test {
  //   display: contents;
  // }
}

/********** Featured **********/
@container style(--featured: true) {
  .title {
    padding-bottom: 1rem;
  }
  .media {
    grid-column: 2/4;
  }

  .meta {
    padding-bottom: 1rem;
  }

  .desc {
    grid-row: 2;
    grid-column: 1;
  }
}

@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)) {
  //outline: solid 2px red;
  grid-template-columns: 1fr;

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

    .desc {
      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 {
    //display: contents;
    grid-column: 2/3;
    grid-row: 1;
  }

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

  .media {
    grid-column: 1;
  }

  .desc-test {
    display: block;
  }
}

.other-content {
  padding-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  //outline: solid 2px red;
}

/* other styles */
.spacer {
  height: 2rem;
  border: 0;
}

/* 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