Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <header>
	<h1 class="page-title">CSS Grid Layout Demo 5</h1>
	<p class="intro">Playing with grid-gap.</p>
</header>

<aside class="demo">
	<section class="grid-px">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>

	<section class="grid-rem">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-em">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-percent">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-fr">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-vw">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-vh">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-ch">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-in">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
		<section class="grid-ex">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
		<section class="grid-mm">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
		<section class="grid-in">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-pc">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
	
	<section class="grid-pt">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</section>
</aside>

<footer>
	<!-- CSS Grid Layout browser support text -->
	[[[https://codepen.io/stacy/pen/f1639a51a21481925379ac4580c6fe2e]]]
</footer>

<!-- Support Message -->
[[[https://codepen.io/stacy/pen/NbvaNY]]]


              
            
!

CSS

              
                // Grid Demo Important CSS Stuff

section {
	display: grid;
	grid-template-columns: 50% 1fr 1fr;
	grid-template-rows: 50px 100px 50px;
}

$units: (
	px: 8px, 
	rem: 0.5rem,
	percent: 4%,
	fr: 1,
	ch: 1ch,
	ex: 1ex,
	em: 0.5em,
	cm: 1cm, 
	mm: 3mm, 
	in: 0.125in, 
	pt: 10pt, 
	pc: 1pc,
	vh: 2vh,
	vw: .65vw,
	vmin: 1vmin,
	vmax: 1vmax
);

@each $unitname, $unitvalue in $units {
	.grid-#{$unitname} {
		grid-gap: #{$unitvalue};

		div:first-child {
			&:after {
				content: '#{$unitname}';
			}
		}
	}	
}


// Color Variables for demo

$g1-color-1: hsl(170, 32%, 53%);
$g1-color-2: complement($g1-color-1);

$steps: 5;

// Mix colors to go from $color-1 ro @color-2 with 9 total steps
@for $i from 0 to $steps {
	div:nth-of-type(#{$i + 1}) {
		background: mix($g1-color-1, $g1-color-2, percentage($i / ($steps - 1)));
	}
}

div {
	&:first-of-type { 
		//	grid-column-start: 1;
		//	grid-column-end: 2;
		// grid-column is short-hand for the above two properties 
		grid-column: 1 / 2;

		// grid-row-start: 1; 
		// grid-row-end: 4; 
		// grid-row is short-hand for the above two properties 
		grid-row: 1 / 3;
	}
	
	// start div 2 at the second grid line and end at the 4th grid line
	// only in row 1
	&:nth-of-type(2) {
		grid-column: 2 / 4;
		grid-row: 1;
	}
	
	// start 5th grid item on grid line 1 and end on line 4 
	&:nth-of-type(5) { 
		grid-column: 1 / 4;
		grid-row: 3;
	}
}


// For fun styles

@import 'https://fonts.googleapis.com/css?family=Patua+One';

body {
	background: #3e3e3e;
	color: white;
	font-family: 'Patua One', serif;
	margin: 2rem;
	-webkit-font-smoothing: antialiased;
}

.page-title {
	font-size: 2rem;
	margin: 0;
}

header{
	margin: 2rem auto;
}

p {
	font-size: 1rem;
	margin: .5rem 0 1.5rem;
}
section {
	font-size: 1.23rem;
}

footer {
	margin: 4rem 0 0;
	max-width: 40rem;
}

a {
	color: hsl(181, 74%, 46%);
}

div {
	padding: .5rem;
}

.demo {
	display: grid;
	grid-template-columns: 1fr;
	grid-gap: 1rem;

	@include bp(small) {
		grid-template-columns: 1fr 1fr;
	}
	
	@include bp(large) {
		grid-gap: 2rem;
		grid-template-columns: 1fr 1fr 1fr 1fr;
	}
}

              
            
!

JS

              
                
              
            
!
999px

Console