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

              
                <!--
  Copyright (c) 2020 - present, DITDOT Ltd.
  https://www.ditdot.hr/en
-->

<div class="cards-container">

    <!-- FIRST CARD -->
    <div class="card card-first">
        <div class="card-header-wrapper">
            <h2 class="card-title">The cosmos awaits</h2>
            <h4 class="card-subtitle">Great turbulent clouds</h4>
            <div class="card-avatar-wrapper">
                <img class="card-avatar"
                    src="https://images.unsplash.com/photo-1476814607969-0dfe98b9be5c?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                    alt="">
            </div>
        </div>
        <div class="card-photo-wrapper">
            <img class="card-photo"
                src="https://images.unsplash.com/photo-1512547770769-0eb554dbaa73?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                alt="">
        </div>
        <p class="card-text">With pretty stories for which there's little good evidence star stuff harvesting star light circumnavigated invent the universe billions upon billions of brilliant syntheses.</p>
        <svg class="card-like" height="32" width="32" style="enable-background:new 0 0 32 32;" version="1.1"
            viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
            <path
                d="M340.8 98.4c50.7 0 91.9 41.3 91.9 92.3 0 26.2-10.9 49.8-28.3 66.6L256 407.1 105 254.6c-15.8-16.6-25.6-39.1-25.6-63.9 0-51 41.1-92.3 91.9-92.3 38.2 0 70.9 23.4 84.8 56.8 13.7-33.3 46.5-56.8 84.7-56.8m0-15.4C307 83 276 98.8 256 124.8c-20-26-51-41.8-84.8-41.8C112.1 83 64 131.3 64 190.7c0 27.9 10.6 54.4 29.9 74.6L245.1 418l10.9 11 10.9-11 148.3-149.8c21-20.3 32.8-47.9 32.8-77.5C448 131.3 399.9 83 340.8 83z" />
        </svg>
        <button class="card-button">More</button>
    </div>

    <!-- SECOND CARD -->
    <div class="card card-second">
        <div class="card-header-wrapper">
            <h2 class="card-title">Harvesting star light</h2>
            <h4 class="card-subtitle">Realm of the galaxies</h4>
            <div class="card-avatar-wrapper">
                <img class="card-avatar"
                    src="https://images.unsplash.com/photo-1583994009906-c00c0bd8acb2?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                    alt="">
            </div>
        </div>
        <div class="card-photo-wrapper">
            <img class="card-photo"
                src="https://images.unsplash.com/photo-1503389152951-9f343605f61e?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                alt=""></div>
        <p class="card-text">Descended from astronomers encyclopaedia galactica Sea of Tranquility encyclopaedia galactica vanquish the impossible courage of our questions. Great turbulent clouds emerged into consciousness inconspicuous motes of rock and gas gathered by gravity.</p>
        <svg class="card-like" height="32" width="32" style="enable-background:new 0 0 32 32;" version="1.1"
            viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
            <path
                d="M340.8 98.4c50.7 0 91.9 41.3 91.9 92.3 0 26.2-10.9 49.8-28.3 66.6L256 407.1 105 254.6c-15.8-16.6-25.6-39.1-25.6-63.9 0-51 41.1-92.3 91.9-92.3 38.2 0 70.9 23.4 84.8 56.8 13.7-33.3 46.5-56.8 84.7-56.8m0-15.4C307 83 276 98.8 256 124.8c-20-26-51-41.8-84.8-41.8C112.1 83 64 131.3 64 190.7c0 27.9 10.6 54.4 29.9 74.6L245.1 418l10.9 11 10.9-11 148.3-149.8c21-20.3 32.8-47.9 32.8-77.5C448 131.3 399.9 83 340.8 83z" />
        </svg>
        <button class="card-button">More</button>
    </div>

    <!-- THIRD CARD -->
    <div class="card card-third">
        <div class="card-header-wrapper">
            <h2 class="card-title">Impossible courage of our questions</h2>
            <h4 class="card-subtitle">The ash of stellar alchemy</h4>
            <div class="card-avatar-wrapper">
                <img class="card-avatar"
                    src="https://images.unsplash.com/photo-1511546395756-590dffdcdbd1?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                    alt="">
            </div>
        </div>
        <div class="card-photo-wrapper"><img class="card-photo"
                src="https://images.unsplash.com/photo-1485846753954-dff2171ddb2b?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                alt=""></div>
        <p class="card-text">Brain is the seed of intelligence from which we spring not a sunrise but a galaxyrise consciousness take root and flourish Cambrian explosion. Stirred by starlight billions upon billions vanquish the impossible the sky calls to us with pretty stories?</p>
        <svg class="card-like" height="32" width="32" style="enable-background:new 0 0 32 32;" version="1.1"
            viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
            <path
                d="M340.8 98.4c50.7 0 91.9 41.3 91.9 92.3 0 26.2-10.9 49.8-28.3 66.6L256 407.1 105 254.6c-15.8-16.6-25.6-39.1-25.6-63.9 0-51 41.1-92.3 91.9-92.3 38.2 0 70.9 23.4 84.8 56.8 13.7-33.3 46.5-56.8 84.7-56.8m0-15.4C307 83 276 98.8 256 124.8c-20-26-51-41.8-84.8-41.8C112.1 83 64 131.3 64 190.7c0 27.9 10.6 54.4 29.9 74.6L245.1 418l10.9 11 10.9-11 148.3-149.8c21-20.3 32.8-47.9 32.8-77.5C448 131.3 399.9 83 340.8 83z" />
        </svg>
        <button class="card-button">More</button>
    </div>

    <!-- FOURTH CARD -->
    <div class="card card-fourth">
        <div class="card-header-wrapper">
            <h2 class="card-title">A mote of dust suspended in a sunbeam</h2>
            <h4 class="card-subtitle">Interiors of collapsing stars</h4>
            <div class="card-avatar-wrapper">
                <img class="card-avatar"
                    src="https://images.unsplash.com/photo-1553669006-0b3882afea8d?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                    alt="">
            </div>
        </div>
        <div class="card-photo-wrapper">
            <img class="card-photo"
                src="https://images.unsplash.com/photo-1498452572341-c087c3ee25fc?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
                alt="">
        </div>
        <p class="card-text">Orion's sword venture take root and flourish inconspicuous motes of rock and gas vanquish the impossible muse about. A very small stage in a vast cosmic arena two ghostly white figures in coveralls and helmets.</p>
        <svg class="card-like" height="32" width="32" style="enable-background:new 0 0 32 32;" version="1.1"
            viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
            <path
                d="M340.8 98.4c50.7 0 91.9 41.3 91.9 92.3 0 26.2-10.9 49.8-28.3 66.6L256 407.1 105 254.6c-15.8-16.6-25.6-39.1-25.6-63.9 0-51 41.1-92.3 91.9-92.3 38.2 0 70.9 23.4 84.8 56.8 13.7-33.3 46.5-56.8 84.7-56.8m0-15.4C307 83 276 98.8 256 124.8c-20-26-51-41.8-84.8-41.8C112.1 83 64 131.3 64 190.7c0 27.9 10.6 54.4 29.9 74.6L245.1 418l10.9 11 10.9-11 148.3-149.8c21-20.3 32.8-47.9 32.8-77.5C448 131.3 399.9 83 340.8 83z" />
        </svg>
        <button class="card-button">More</button>
    </div>
</div>
<div>

    <p class="caption">
        <a href="https://www.ditdot.hr/en/css-subgrid-how-to-build-complex-layouts-in-a-simple-way"
            title="ditdot.hr" target="_blank">Visit how-to article on our blog</a>
    </p>
</div>
              
            
!

CSS

              
                /*
    Copyright (c) 2020 - present, DITDOT Ltd.
    https://www.ditdot.hr/en
*/

html {
  font-size: 12px;
  font-size: clamp(11px, 3vw, 14px);
  /* define flexible rem size */
  font-family: Roboto, Arial, sans-serif;
  line-height: 1.4;
}

body {
  background-color: #EEF3F6;
  color: #222;
  margin: 0;
}

/* MAIN GRID */

.cards-container {
  max-width: 1400px;
  margin: 2rem auto;
  width: 95%;
  display: grid;
  /* set display to grid to create the outer grid */
  grid-template-columns: repeat(3, [col-start] fit-content(9rem));
  /* create 4 explicit column tracks */
  grid-auto-rows: fit-content(12rem) minmax(10rem, 14rem) auto auto;
  /* create 4 implicit row tracks */
  gap: 0.5rem;
  /* create the gap between grid columns and rows */
  justify-content: center;
}

/* SUBGRID */

.card {
  grid-column: span 3;
  /* every card spans across 3 columns of the main grid */
  grid-row: span 4;
  /* every card spans across 4 rows of the main grid */
  display: grid;
  /* set display to grid in order to create a subgrid */
  grid-template-columns: subgrid [card-start][button-start][col][card-end button-end];
  /* create subgrid for columns to use grid column tracks of the parent and name the column lines*/
  grid-template-rows: subgrid [title-start][title-end photo-start] [photo-end text-start] [text-end button-start] [button-end];
  /* create subgrid for rows to use row column tracks of the parent and name the row lines*/
  row-gap: 0;
  /* override the inherited row gap */
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  margin: 0 0.5rem 1rem 0.5rem;
  padding: 1rem;
  /*padding influences the sizing of rows and columns*/
}

/* SUBGRID IN SUBGRID */

.card-header-wrapper {
  grid-column: card;
  /* use named tracks to place elements inside the subgrid */
  grid-row: title;
  display: grid;
  /* make it grid container to create another subgrid inside */
  grid-template-columns: subgrid;
  /* create subgrid for columns to use grid column tracks of the parent */
  grid-template-rows: fit-content(6rem) fit-content(6rem);
  /* create two independent rows */
  grid-template-areas: "subtitle subtitle avatar" "title title title";
  /* create named grid areas to place the header elements*/
  align-items: end;
  font-family: "Open Sans", Arial, sans-serif;
}

/* CARD DETAILS */

.card-title {
  grid-area: title;
  /* place card title in the named grid area*/
  font-size: 1.25rem;
}

.card-subtitle {
  grid-area: subtitle;
  font-weight: normal;
  margin: 0;
}

.card-avatar-wrapper {
  grid-area: avatar;
  align-self: start;
  justify-self: end;
}

.card-avatar {
  object-fit: cover;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
}

.card-photo-wrapper {
  grid-column: card;
  grid-row: photo;
  margin-bottom: 0.5rem;
}

.card-photo {
  object-fit: cover;
  width: 100%;
  height: 100%;
}

.card-text {
  grid-column: col-start / span 3;
  /* use main grid line names*/
  grid-row: text;
  margin-bottom: 2rem;
}

.card-like {
  grid-column: 1/2;
  grid-row: button;
  width: 2.5rem;
  height: 2.5rem;
  align-self: end;
  cursor: pointer;
}

.card-button {
  grid-area: button;
  min-width: 4rem;
  height: 3rem;
  background-color: #66A9D6;
  border: none;
  border-radius: 0.25rem;
  padding: 0 0.75rem;
  color: white;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.09rem;
  cursor: pointer;
  justify-self: end;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 8rem;
}

p.caption {
  text-align: center;
  font-size: 13px;
  padding-bottom: 30px;
}

p.caption a {
  color: #0086B3;
}

/* browsers without support for the subgrid feature */

@supports not (grid-template-columns: subgrid) {
  .card {
    grid-template-columns: repeat(3, [col-start] fit-content(9rem));
    grid-template-rows: 9rem 15rem auto auto;
  }

  .card-header-wrapper, .card-photo-wrapper, .card-text {
    grid-column: 1/-1;
    grid-row: span 1;
  }

  .card-text {
    margin-bottom: 0;
  }

  .card-button {
    grid-column: 3/-1;
    align-self: end;
  }

}

@media screen and (min-width: 480px) {
  html {
    font-size: clamp(11px, 2vw, 14px);
  }

  .cards-container {
    grid-template-columns: repeat(6, [col-start] fit-content(9rem));
  }

}

@media screen and (min-width: 1024px) {
  html {
    font-size: clamp(11px, 1vw, 14px);
  }
  
  .cards-container {
    grid-template-columns: repeat(12, [col-start] fit-content(9rem));
  }

}

/*
This example is not supported in Internet Explorer
*/
              
            
!

JS

              
                
              
            
!
999px

Console