<div class="page-wrap">
  <resize-asaurus>
    <div class="card">
      <img src='https://images.unsplash.com/photo-1554917420-44e47b14a75c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ' alt=''>
      <div class="card-content">
        <h2>Card Component</h2>
        <p>A basic card component with an image, title, description, and call to action. By default, the image is on top and full-width, but inside larger containers the image is positioned on the left with the rest of the content beside it.</p>
      </div>
    </div>
  </resize-asaurus>
  <resize-asaurus>
    <div class="card">
      <img src='https://images.unsplash.com/photo-1554917420-44e47b14a75c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ' alt=''>
      <div class="card-content">
        <h2>Card Component</h2>
        <p>A basic card component with an image, title, description, and call to action. By default, the image is on top and full-width, but inside larger containers the image is positioned on the left with the rest of the content beside it.</p>
      </div>
    </div>
  </resize-asaurus>
</div>
.card {
  flex: 1;
  padding: 1rem;
  background: white;
  border: 1px solid #eee;
  border-radius: 8px;
  min-width: 180px;
  container: card / inline-size;
  h2 {
    margin: 0 0 1rem 0;
    line-height: 1.1;
    font-size: clamp(1.4rem, 1rem + 5cqi, 4rem);
  }
  img {
    width: 100%;
    display: block;
    margin: 0 0 1rem 0;
  }
}

.page-wrap {
  display: grid;
  gap: 1rem;
  grid-template-columns: min-content 1fr;
  align-items: start;
}

body {
  font: 90%/1.4 system-ui;
}

.resizeasaurus-size {
  display: none;
}
@supports (resize: horizontal) {
  .resizeasaurus {
    display: block;
    padding: 0;
    resize: horizontal;
    overflow: auto;
  }
  /* Workaround for Safari refusing to go below initial content width */
  .resizeasaurus:active {
    width: var(--resizeasaurus-initial-width, 1px);
  }
  .resizeasaurus-size {
    display: block;
    text-align: right;
    bottom: 0;
    padding-right: 1.5em;
    font-size: 0.8125em; /* 13px /16 */
    color: #666;
  }
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/resizeasaurus.js