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

              
                <main class="main">
	<h1>Conditional CSS grid template areas</h1>

	<div class="card-container">
		<section class="cards">
			<article class="card card--one">
				<h2>Card 1</h2>
				<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
			</article>

			<article class="card card--two">
				<h2>Card 2</h2>
				<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
			</article>

			<div class="cards-sidebar">
				<article class="card card--three">
					<h2>Card 3</h2>
					<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
				</article>

				<article class="card card--four">
					<h2>Card 4</h2>
					<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
				</article>

				<article class="card card--five">
					<h2>Card 5</h2>
					<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
				</article>
			</div>
		</section>
	</div>
</main>
              
            
!

CSS

              
                /*
Three different layouts with one set of HTML and optionally used inner container div.

This layout has two breakpoints; one at 30rem (~480px), and one at 60rem (~960px).
Take note of `grid-template-areas` and `display: contents;` in the CSS.

This code uses the following, optional technologies unavailable in old browsers:

* container queries: https://caniuse.com/css-container-queries;
* selector nesting: https://caniuse.com/css-nesting;
* logical properties: https://caniuse.com/css-logical-props.

Card background colors courtesy of:
https://stephango.com/flexoki
*/

body {
	font-size: 1em;
	line-height: 1.6;
	padding-block: 4vh;
	padding-inline: 3vw;
}

.card-container {
	container-name: cards;
	container-type: inline-size;
}

/* Base styles + layout 1 */
.cards {
	display: grid;
	gap: 1rem;
	grid-auto-rows: 1fr;
	grid-template-areas:
		"cards-one"
		"cards-two"
		"cards-three"
		"cards-four"
		"cards-five";

	& .card {
		padding: 1em 1.5em;

		& h2 {
			margin-block-start: 0;
		}
	}

	& .card--one {
		background-color: #faeec6;
		grid-area: cards-one;
	}

	& .card--two {
		background-color: #edeecf;
		grid-area: cards-two;
	}

	& .card--three {
		background-color: #ddf1e4;
		grid-area: cards-three;
	}

	& .card--four {
		background-color: #e1eceb;
		grid-area: cards-four;
	}

	& .card--five {
		background-color: #f0eaec;
		grid-area: cards-five;
	}

	& .cards-sidebar {
		display: contents;
		grid-area: cards-sidebar;
	}
}

/* Layout 2 */
@container cards (30rem <= width < 60rem) {
	.cards {
		grid-template-areas:
			"cards-one cards-sidebar"
			"cards-two cards-sidebar";

		& .cards-sidebar {
			display: flex;
			flex-direction: column;
			gap: 1rem;
		}
	}
}

/* Layout 3 */
@container cards (width >= 60rem) {
	.cards {
		/* You must provide the same number of columns in each row, hence the replicated names below: */
		grid-template-areas:
			"cards-one  cards-one  cards-two  cards-two  cards-three cards-three"
			"cards-four cards-four cards-four cards-five cards-five  cards-five";
	}
}

              
            
!

JS

              
                
              
            
!
999px

Console