cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div class="grid">
	<div class="grid__item grid__item--lg">
		<div class="caption">
			<h1>Aspect ratio grid - responsive</h1>
			<p>16:9 on small screens, 1:1 on larger screens</p>
		</div>
		<img src="https://images.unsplash.com/photo-1509408895711-7eda6e83c637?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=1844cab997dc2e5f1ce14e3b9cbd0bc1&auto=format&fit=crop&w=1500&q=80" alt="Starry sky" width="100%" height="auto">
	</div>
	<div class="grid__item grid__item--sm"></div>
	<div class="grid__item grid__item--sm"></div>
	<div class="grid__item grid__item--db">
		<p>Stars are luminous spheres made of plasma – a superheated gas threaded with a magnetic field. They are made mostly of hydrogen, which stars fuse in their cores. That process releases energy, which pushes against the weight of the outer layers of the star and keeps it stable. The energy is also released as heat and light, which are radiated out to space. Stars are the main components of galaxies, and were among the first objects to form in the early universe. The closest star to Earth is the Sun.</p>
	</div>
	<div class="grid__item grid__item--lg grid__item--right">
		<img src="https://images.unsplash.com/photo-1502656109408-152680a8ad1c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=40e160d54f5831df3d12204916d8edb1&auto=format&fit=crop&w=1950&q=80" alt="Starry sky" width="100%" height="auto">
	</div>
	<div class="grid__item grid__item--sm"></div>
	<div class="grid__item grid__item--db">
		<p>Star formation happens in clouds of interstellar gas and dust called “nebulae”. These clouds are mostly molecular hydrogen, and are often referred to as HII regions. The process begins when the cloud is nudged into a spinning motion, perhaps by a shock wave from a nearby supernova explosion. Clumps begin to form, and they get hotter and hotter as they gain more mass. When the temperature inside such a “young stellar object” reaches 10 million degrees Celsius, a process called “nuclear fusion” ignites, and a star is born.</p>
		<p><a href="https://space-facts.com/stars/">space-facts.com</a></p>
	</div>
	<div class="grid__item grid__item--sm"></div>
</div>
            
          
!
            
              * {
	box-sizing: border-box;
}

img {
	height: 100%;
	width: 100%;
	display: block;
	object-fit: cover;
}

:root {
	// We just need to know these 3 values up front:
	--gutter: 10px;
	--wrapper: calc(100vw - ( 2 * var(--gutter)));
	
	--noOfColumns: 2;
	
	// Number of gutters is columns minus 1:
	--noOfGutters: calc(var(--noOfColumns) - 1);
	
	// Aspect ratio goes here:
	--ratioA: 16;
	--ratioB: 9;
	
	// Use the aspect ratio to calculate the factor for multiplication:
	--factor: calc(var(--ratioB) / var(--ratioA));
	
	// Calculating the row height:
	--rh: calc(( (var(--wrapper) - (var(--noOfGutters) * var(--gutter))) 
		/ var(--noOfColumns)) * var(--factor));
	
	@media (min-width: 60em) {
		--wrapper: 60em;
		--gutter: 20px;
		--noOfColumns: 4;
		--ratioA: 1;
		--ratioB: 1;
	}
}

.grid {
	max-width: var(--wrapper);
	display: grid;
	grid-template-columns: repeat(var(--noOfColumns), minmax(0, 1fr));
	grid-auto-flow: dense;
	grid-auto-rows: minmax(var(--rh), auto); // If the content is taller then the box will grow to fit. This is only going to work if the column value is 1fr
	grid-gap: var(--gutter);
	margin: var(--gutter);
	
	@media (min-width: 60em) {
		margin: var(--gutter) auto;
	}
}

.grid__item {
	background-color: steelBlue;
}

.grid__item--lg {
	grid-column: span 2;
	grid-row: span 2;
	background-color: blue;
	position: relative;
}

.grid__item--right {
	@media (min-width: 60em) {
		grid-column: 3 / span 2;
	}
}

.grid__item--db {
	grid-column: span 2;
	background-color: lightBlue;
	padding: 1.5em;
	
	@media (min-width: 60em) {
		background-color: transparent;
		padding: 0;
	}
}

.caption {
	position: absolute;
	width: 100%;
	height: 100%;
	padding: 1.5em;
	color: white;
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console