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

              
                <body>
	<div class="notification">
		<p class="notification__floats">Using floats</p>
		<p class="notification__grid">Using CSS Grid</p>
	</div>
	<ul class="grid">
		<li class="card header">
			<h1>Which foods do you like?</h1>
			<p>Tell us what you crave for and we'll get you the tasty bits</p>
		</li>
	
		<li class="card">
			<a href="https://www.freepik.com/free-photo/delicious-salami-pizza_800502.htm">
				<h2>Pizza</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/20130114016-3-cropped.jpg" alt="A salami pizza">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/french-fries_1166511.htm">
				<h2>Fries</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532559/tumblr/1402-cropped.jpg" alt="Some French fries">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/plate-basil-cherry-gourmet-menu_1119851.htm">
				<h2>Pasta</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/1184-cropped.jpg" alt="Spaghetti pomodoro">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/assorted-selection-of-freshly-made-buns_1757786.htm">
				<h2>Bread</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/249541-P3VU6S-681-cropped.jpg" alt="Some bread buns">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/decorative-fast-food-composition_1333702.htm">
				<h2>Junk</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/183551-OWW4VX-649-cropped.jpg" alt="Junk food">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/sandwich-with-chips_2212274.htm">
				<h2>Sandwich</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/156-cropped.jpg" alt="A sandwich">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/slice-of-new-york-cheesecake_1009317.htm">
				<h2>Cheesecake</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/2130-cropped.jpg" alt="Cheesecake">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/portion-beefsteak-dining-meal-barbecued_1047516.htm">
				<h2>Meat</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/322-cropped.jpg" alt="Meat with fries">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/cinnamon-near-spilled-coffee-beans_1815239.htm">
				<h2>Coffee</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/253284-P46VZ2-495-cropped.jpg" alt="Coffee beans scattered on a table">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/chocolate-chunk_964578.htm">
				<h2>Chocolate</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/OFN9XN0-cropped.jpg" alt="Some chocolate">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/ice-cream-background_2333047.htm">
				<h2>Ice cream</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/325412-P9FXDW-955-cropped.jpg" alt="Ice cream">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/cupcakes-with-sprinkles-and-flags_1330134.htm">
				<h2>Cupcakes</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/155547-OUES41-497-cropped.jpg" alt="Colored cupcakes">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/cream-pastry-sweet-white-tasty_1089959.htm">
				<h2>Creamy</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/6033-cropped.jpg" alt="A creamy cake">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/bunch-of-colorful-candies_1369655.htm">
				<h2>Candies</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/173028-OVWF2H-785-cropped.jpg" alt="Lots of candies">
			</a>
		</li>
		
		<li class="card">
			<a href="https://www.freepik.com/free-photo/delicious-salami-pizza_800502.htm">
				<h2>Pizza</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/20130114016-3-cropped.jpg" alt="A salami pizza">
			</a>
		</li>
		
		<li class="card">
			<a href="https://www.freepik.com/free-photo/french-fries_1166511.htm">
				<h2>Fries</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532559/tumblr/1402-cropped.jpg" alt="Some French fries">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/plate-basil-cherry-gourmet-menu_1119851.htm">
				<h2>Pasta</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/1184-cropped.jpg" alt="Spaghetti pomodoro">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/assorted-selection-of-freshly-made-buns_1757786.htm">
				<h2>Bread</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/249541-P3VU6S-681-cropped.jpg" alt="Some bread buns">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/decorative-fast-food-composition_1333702.htm">
				<h2>Junk</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/183551-OWW4VX-649-cropped.jpg" alt="Junk food">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/sandwich-with-chips_2212274.htm">
				<h2>Sandwich</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/156-cropped.jpg" alt="A sandwich">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/slice-of-new-york-cheesecake_1009317.htm">
				<h2>Cheesecake</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/2130-cropped.jpg" alt="Cheesecake">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/portion-beefsteak-dining-meal-barbecued_1047516.htm">
				<h2>Meat</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/322-cropped.jpg" alt="Meat with fries">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/cinnamon-near-spilled-coffee-beans_1815239.htm">
				<h2>Coffee</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/253284-P46VZ2-495-cropped.jpg" alt="Coffee beans scattered on a table">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/chocolate-chunk_964578.htm">
				<h2>Chocolate</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/OFN9XN0-cropped.jpg" alt="Some chocolate">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/ice-cream-background_2333047.htm">
				<h2>Ice cream</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532558/tumblr/325412-P9FXDW-955-cropped.jpg" alt="Ice cream">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/cupcakes-with-sprinkles-and-flags_1330134.htm">
				<h2>Cupcakes</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/155547-OUES41-497-cropped.jpg" alt="Colored cupcakes">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/cream-pastry-sweet-white-tasty_1089959.htm">
				<h2>Creamy</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/6033-cropped.jpg" alt="A creamy cake">
			</a>
		</li>
		<li class="card">
			<a href="https://www.freepik.com/free-photo/bunch-of-colorful-candies_1369655.htm">
				<h2>Candies</h2>
				<img src="https://res.cloudinary.com/mgiulio/image/upload/v1530532557/tumblr/173028-OVWF2H-785-cropped.jpg" alt="Lots of candies">
			</a>
		</li>
	</ul>
</body>
              
            
!

CSS

              
                /*
 * Sass stuff
 */
 
$item-size: 210px;
$col-gutter: 10px;
$vp-gutter: $col-gutter;
$max-cols: 5;
$scrollbar-size: 20px;

@function grid-width($num-cols) {
	@return $num-cols * $item-size + ($num-cols - 1) * $col-gutter;
}

@mixin when-n-cols($n) {
	@media screen and (min-width: #{grid-width($n) + 2 * $vp-gutter + $scrollbar-size}) {
		@content;
	}
}

/*
 * Basics
 */

body {
	margin: 0;
	font-size: 16px;
	background-color: #222;
	color: #fff;
}

img {
	border: none;
}

/*
 * Common layout code
 */
 
.grid {
	margin: 0;
	padding: 0;
	list-style: none;
	
	margin: 40px auto;
	padding-left: $vp-gutter;
	padding-right: $vp-gutter;
}

/*
 * Float layout
 */

.grid {
	width: grid-width(1);
	
	.card {
		float: left;
		width: $item-size;
		height: $item-size;
		margin: 0;
		margin-bottom: $col-gutter;
	}
	
	&::after {
		content: '';
		display: table;
		clear: both;
	}
	
	@include when-n-cols(2) {
		width: grid-width(2);
		.card:nth-child(2n) {
			margin-right: $col-gutter;
		}
		.header {
			$header-size: grid-width(2);
			width: $header-size;
			height: $header-size;
		}
	}
	
	@include when-n-cols(3) {
		width: grid-width(3);
		.card {
			margin-right: $col-gutter;
		}
		.card:nth-child(2),
		.card:nth-child(3),
		.card:nth-child(3n + 6)
		{
			margin-right: 0;
		}
	}
	
	@include when-n-cols(4) {
		width: grid-width(4);
		.card,
		.card:nth-child(2),
		.card:nth-child(3),
		.card:nth-child(3n + 6)
		{
			margin-right: $col-gutter;
		}
		.card:nth-child(3),
		.card:nth-child(5),
		.card:nth-child(4n + 9)
		{
			margin-right: 0;
		}
	}
	
	@include when-n-cols(5) {
		width: grid-width(5);
		.card:nth-child(3),
		.card:nth-child(5),
		.card:nth-child(4n + 9)
		{
			margin-right: $col-gutter;
		}
		.card:nth-child(4),
		.card:nth-child(7),
		.card:nth-child(5n + 12)
		{
			margin-right: 0;
		}
	}
	
}

/*
 * CSS Grid Layout overrides the previous float layout on supporting browsers
 */
 
.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, $item-size);
	grid-auto-rows: $item-size;
	grid-gap: $col-gutter;
	
	justify-content: center;
}

@supports (display: grid) {
	.grid {
		width: auto;
		max-width: grid-width($max-cols);
		.card {
			margin: 0 !important;
		}
	}
}

@include when-n-cols(2) {
	.grid .header {
		grid-row: span 2;
		grid-column: span 2;
	}
}

/*
 * Cards
 */
 
.grid .card {
	transition-property: transform;
	transition-duration: 0.3s;
	
	transition-property: -webkit-transform;
  transition-property: transform;
  transition-property: transform, -webkit-transform;
	
	background-color: #333;
}
 
.grid .card a {
	display: block;
	width: 100%;
	height: 100%;
	
	position: relative;
}

.grid .card img {
	display: block;
	width: 100%;
	height: 100%;
	-o-object-fit: cover;
	object-fit: cover;
}

.grid .card h2 {
	margin: 0;
	
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	
	padding: 10px;
	
	text-decoration: none;
	font-family: Raleway, sans-serif;
	font-weight: normal;
	font-size: 1em;
	letter-spacing: 1px;
	
	color: #fff;
	
	background: rgba(0,0,0, 0.2);
	background: radial-gradient(ellipse at center, transparent 0, rgba(0,0,0, .36) 100%);
}

.grid .card:hover {
	-webkit-transform: scale(0.95);
	-ms-transform: scale(0.95);
	transform: scale(0.95);
}

.grid .header:hover {
	-webkit-transform: none;
	-ms-transform: none;
	transform: none;
}

/* Focus style as hovering, if possible */
.grid .card a:focus {
	outline: 2px solid #d11ee9;
}
.grid .card:focus-within {
	-webkit-transform: scale(0.95);
	-ms-transform: scale(0.95);
    transform: scale(0.95);
}
.grid .card:focus-within a:focus {
	outline: none;
}

.grid .header {
	box-sizing: border-box;

	text-align: center;
	padding-top: 23px;
	
	font-size: 1.6875em;
	line-height: 1.3;
	
	background: radial-gradient(ellipse at center, transparent 0, rgba(0,0,0, 0.48) 100%) hsla(0, 0%, 27%, 1);
}

.grid .header h1 {
	margin-top: 0;
	margin-bottom: 0.67em;
	
	font-family: 'Cherry Swash', cursive;
	text-transform: capitalize;
	font-size: 1em;
	font-weight: normal;
	
	padding-left: 28px;
	padding-right: 28px;
}

.grid .header p {
	margin: 0;
	
	font-family: 'Raleway', sans-serif;
	font-size: 0.52em;
	
	padding-left: 34px;
	padding-right: 34px;
	
	color: #c7c7c7;
}

@include when-n-cols(2) {
	.grid .header {
		font-size: 2.5em;
		
		padding-top: 100px;
	}
	
	.grid .header h1 {
		padding-left: 80px;
		padding-right: 80px;
	}

	.grid .header p {
		padding-left: 120px;
		padding-right: 120px;
	}
}

/*
 * Show the used layout method
 */

.notification {
	position: fixed;
	top: 0;
	left: 0;
	
	font-family: 'Raleway', sans-serif;
	font-size: 20px;
	line-height: 30px;
	padding: 0 20px;
	
	background-color: red;
	color: white;
	
	-webkit-animation-name: hide;
    animation-name: hide;
	-webkit-animation-duration: 1s;
	animation-duration: 1s;
	-webkit-animation-delay: 2s;
	animation-delay: 2s;
	-webkit-animation-iteration-count: 1;
	animation-iteration-count: 1;
	-webkit-animation-fill-mode: forwards;
	animation-fill-mode: forwards;
}

.notification__grid {
	display: none;
}

@supports (display: grid) {
	.notification__floats {
		display: none;
	}
	.notification__grid {
		display: block;
	}
}

@-webkit-keyframes hide {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@keyframes hide {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}


              
            
!

JS

              
                
              
            
!
999px

Console