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

              
                <section class="news">
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=1');"></div>
		<div class="caption">
			<h1 class="title">Distinctio sunt similique quos error, solestiae illo placeat</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=2');"></div>
		<div class="caption">
			<h1 class="title">Explicabo ducimus ipsam vel nostrum nesciunt colestiae distinctio</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=3');"></div>
		<div class="caption">
			<h1 class="title">Aliquam nisi labore beatae at optio rerum illum</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=4');"></div>
		<div class="caption">
			<h1 class="title">Eligendi distinctio laborum sapiente voluptatem quidem quas numquam</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=5');"></div>
		<div class="caption">
			<h1 class="title">Veniam veritatis eligendi cumque porro modi quos vero repellendus ipsam aperiam</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=6');"></div>
		<div class="caption">
			<h1 class="title">Nisi repudiandae hic iste ratione accusamus vero accusantium</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=7');"></div>
		<div class="caption">
			<h1 class="title">Quasi laudantium molestias aliquam adipisci dolores recusandae ab</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
	<article class="post">
		<div class="media" style="background-image: url('https://picsum.photos/1600/900?random=8');"></div>
		<div class="caption">
			<h1 class="title">Aut laudantium placeat quos inventore quibusdam magnam</h1>
			<div class="author">by John Doe</div>
		</div>
	</article>
	
</section>
              
            
!

CSS

              
                @mixin scrim($direction: to top, $color: #000, $alpha-from: 1, $alpha-to: 0) {
	$diff: $alpha-from - $alpha-to;
	background: linear-gradient(
		$direction,
		rgba($color, $alpha-from) 0%,
		rgba($color, $alpha-from - $diff*0.7) 50%,
		rgba($color, $alpha-from - $diff*0.85) 65%,
		rgba($color, $alpha-from - $diff*0.925) 75.5%,
		rgba($color, $alpha-from - $diff*0.963) 82.85%,
		rgba($color, $alpha-from - $diff*0.981) 88%,
		rgba($color, $alpha-to) 100%
	);
}

* {
	box-sizing: border-box;
	font-family: Roboto, sans-serif;
}

h1, h2, h3, h4, h5, h6 {
	font-family: Lora, serif;
}

body {
	margin: 0;
}

.news {
	display: grid;
	grid-template-columns: repeat(12, 1fr);
	grid-auto-rows: 350px;
	grid-auto-flow: dense;
	grid-gap: 1em;
	max-width: 1600px;
	margin: 0 auto;
	padding: 1em;

	.post {
		display: flex;
		flex-flow: column nowrap;

		&:nth-child(1) { grid-column-end: span 9; }
		&:nth-child(2) { grid-column-end: span 3; }
		&:nth-child(3) { grid-column-end: span 3; }
		&:nth-child(4) { grid-column-end: span 6; }
		&:nth-child(5) { grid-column-end: span 3; }
		&:nth-child(6) { grid-column-end: span 6; }
		&:nth-child(7) { grid-column-end: span 3; }
		&:nth-child(8) { grid-column-end: span 3; }

		.media {
			display: block;
			flex: 1 1 auto;
			background-size: cover;
			background-position: center;
			background-color: #ddd;
		}

		.caption {
			padding: .5em 0 0;
			.title { margin: 0 0 .5em; }
			.author { font-style: italic;	}
		}

		&.overlaid {
			position: relative;

			.caption {
				z-index: 2;
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				color: #fff;
				padding: 1em;
			}

			&::after {
				z-index: 1;
				content: '';
				position: absolute;
				top: 0; bottom: 0;
				left: 0; right: 0;
				@include scrim();
			}
		}
	}
}

@media (max-width: 1200px) {
	.news .post {
		&:nth-child(1) { grid-column-end: span 12; }
		&:nth-child(2) { grid-column-end: span 4; }
		&:nth-child(3) { grid-column-end: span 4; }
		&:nth-child(4) { grid-column-end: span 4; }
		&:nth-child(5) { grid-column-end: span 12; }
		&:nth-child(6) { grid-column-end: span 4; }
		&:nth-child(7) { grid-column-end: span 4; }
		&:nth-child(8) { grid-column-end: span 4; }
	}
}

@media (max-width: 900px) {
	.news .post {
		&:nth-child(1) { grid-column-end: span 12; }
		&:nth-child(2) { grid-column-end: span 6; }
		&:nth-child(3) { grid-column-end: span 6; }
		&:nth-child(4) { grid-column-end: span 12; }
		&:nth-child(5) { grid-column-end: span 6; }
		&:nth-child(6) { grid-column-end: span 6; }
		&:nth-child(7) { grid-column-end: span 6; }
		&:nth-child(8) { grid-column-end: span 6; }
	}
}

@media (max-width: 600px) {
	.news .post {
		grid-column-end: span 12 !important;
	}
}
              
            
!

JS

              
                $(document).ready(function() {

	var large = 1200,
			medium  = 900,
			small   = 600,
			highlighted  = 'overlaid';

	function changeNewsArticleClass() {
		var width = $(window).outerWidth();
		
		$('.news .post').removeClass(highlighted);
		
		if (width > large) {
			$('.news .post:nth-child(1), .news .post:nth-child(4), .news .post:nth-child(6)').addClass(highlighted);
		}
		else if (width > medium && width <= large) {
			$('.news .post:nth-child(1), .news .post:nth-child(5)').addClass(highlighted);
		}
		else if (width > small && width <= medium) {
			$('.news .post:nth-child(1), .news .post:nth-child(4)').addClass(highlighted);
		}
		else if (width <= small) {
			$('.news .post').addClass(highlighted);
		}
	}

	changeNewsArticleClass();

	$(window).on('load resize', function() {
		changeNewsArticleClass();
	});

});
              
            
!
999px

Console