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

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

              
                <main>

	<h1>How <em>not</em> to use percentages for height in a flex container</h1>

	<div class="flex-container">
		<div class="column-1">
			<figure class="killed-by-percentages"></figure>
			<h2 class="dead">🤔 Wait a sec, what am I doing out here?</h2>
		</div>
		<div class="column-2">
			<ul class="list-of-things">
				<li>Thing #1</li>
				<li>Thing #2</li>
				<li>Thing #3</li>
			</ul>
		</div>
	</div>

	<div class="we-got-problems">
		<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur possimus temporibus, totam repellat molestias voluptatum placeat voluptates dicta aspernatur, quos quia corrupti, atque architecto magni eos doloribus soluta vero hic.</p>
		<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur possimus temporibus, totam repellat molestias voluptatum placeat voluptates dicta aspernatur, quos quia corrupti, atque architecto magni eos doloribus soluta vero hic.</p>
		<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur possimus temporibus, totam repellat molestias voluptatum placeat voluptates dicta aspernatur, quos quia corrupti, atque architecto magni eos doloribus soluta vero hic.</p>
	</div>

	<section class="til">
		<h2>Today I Learned</h2>
		<p>As soon as you assign a percentage-based height inside a flex child (literally anything inside that affects that child’s height, even grandchild elements), if any element uses a percentage-based height then that height is removed from the parent height calculation.</p>
		<p>The percentage ignores the current column’s height and sets 100% = the next tallest column.</p>
		<p>And then you sob because the rest of your content got pushed outside the container.</p>
	</section>

</main>

              
            
!

CSS

              
                .flex-container {
	display: flex;
}

.column-1 {
	width: 60%;
}

.column-2 {
	width: 40%;
}

.list-of-things li {
	margin-bottom: 1rem;
	padding: 1rem;
	background: lightgray;
}

.killed-by-percentages {
	height: 100%;
	max-height: 200px;
	background: url('https://i.kym-cdn.com/entries/icons/mobile/000/018/012/this_is_fine.jpg') center top / cover no-repeat;
}



/* ------------------------------ */
/* Demo styles                    */
/* ------------------------------ */

body {
	background: tomato;
}

main {
	max-width: 100ch;
	margin: auto;
}

div {
	outline: 1px dotted black;
}

figure {
	margin: 0;
}

.flex-container {
	background: white;
}

.killed-by-percentages {	
	outline: 1px dashed red;
}

.dead {
	background: yellow;
	font-style: italic;
}

.we-got-problems {
	position: relative;
	z-index: -1;
}

.til {
	max-width: 75ch;
	margin: auto;
}
              
            
!

JS

              
                
              
            
!
999px

Console