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

              
                <div class="hero" data-full-height>
	<div class="container">
		<h1>🦸‍♂️ CSS-Only Fix for Full Height Heroes</h1>
		<p>Currently, WebKit-based browsers support <code>-webkit-fill-available</code> for setting the size of an element to the available space in its container.</p>
		<p>This is awesome for solving common height problems, like the classic <a href="https://allthingssmitty.com/2020/05/11/css-fix-for-100vh-in-mobile-webkit/" target="_blank" rel="noopener">100vh issue in mobile WebKit</a>.</p>
		
		<details>
			<summary><strong>But there are still some important gotchas to watch out for…</strong></summary>
			
			<ul>
				<li><strong>Chrome Height Bug</strong>: <a href="https://github.com/postcss/postcss-100vh-fix#readme" target="_blank" rel="noopener">As Sitnick pointed out in his PostCSS plugin</a>, Chrome currently fails to calculate the correct height in some cases (like this pen), so it’s best to use <code>100vh</code> by default and only apply <code>-webkit-fill-available</code> in browsers that need it (e.g., iOS Safari). You can use <code>@supports</code> to work around this for now.</li>
				<li><strong>Safari Orientation Bug</strong>: Unfortunately, iOS Safari incorrectly resets the element height on orientation changes. For example, <a href="https://www.dropbox.com/s/f49gsckvyc6uc3e/2020-08-03%20Safari%20orientation%20bug%20with%20fill-available%20fix%20for%20full%20height%20heroes.mp4?dl=0" target="_blank" rel="noopener">see this screencast</a>. I haven't checked for an official bug report yet, but be careful using this in production in the meantime. YMMV.</li>
				<li><strong>Box Sizing</strong>: As the W3C spec says (see quote below), fit available (aka “stretch fit”) <em>subtracts</em> the current element’s margin/border/padding, so if you have <code>box-sizing: border-box</code> applied you’ll end up shrinking your element by that much. To fix, simply make your element <code>box-sizing: content-box</code>.
					<blockquote>
						<dl>
							<dt><dfn>stretch fit</dfn></dt>
							<dd>The stretch fit into a given size is that size, minus the element’s computed margins (not collapsed, treating <span class="css">auto</span> as zero), border, and padding in the given dimension (such that the outer size is a perfect fit), and flooring at zero (so that the inner size is not negative).
							</dd>
						</dl>
					</blockquote>
				</li>
				<li><strong>Future Keyword</strong>: This fix should help us for a while, but the keyword “fill-available” has changed in the spec, so when it finally lands in browsers as a web standard it will be called “stretch-fit” instead. Don’t worry about it for now, just expect the change later on.</li>
			</ul>
			
			<p>If you’re comfortable with these bugs, here’s some code you can use today:</p>
			<code><pre>.hero {
	min-height: 100vh;
}

<span class="comment">/* Only apply fix in iOS Safari */</span>
@supports (-webkit-touch-callout: none) {
	.hero {
		min-height: -webkit-fill-available;
		<span class="comment">/* Prevent margin/border/padding from shrinking available space */</span>
		box-sizing: content-box;
	}
}</pre></code>
		</details>
		
		<p>P.S. 👋 Shoutout to <a href="https://github.com/postcss/postcss-100vh-fix#readme" target="_blank" rel="noopener">Sitnick’s PostCSS plugin</a> and <a href="https://allthingssmitty.com/2020/05/11/css-fix-for-100vh-in-mobile-webkit/" target="_blank" rel="noopener">Matt Smith’s article</a> for this fix! Huge, huge improvement on the JS hacks we’ve been using for so long. Thank you!</li>
	</div>
</div>

<div class="container" style="margin-bottom: 10rem;">
	<h2>References</h2>
	<ul>
		<li><a href="https://twitter.com/sitnikcode/status/1288097180721377280" target="_blank" rel="noopener">Twitter: Sitnik the Developer: I released a new @PostCSS plugin…</a></li>
		<li><a href="https://github.com/postcss/postcss-100vh-fix#readme" target="_blank" rel="noopener">GitHub: PostCSS 100vh Fix</a></li>
		<li><a href="https://allthingssmitty.com/2020/05/11/css-fix-for-100vh-in-mobile-webkit/" target="_blank" rel="noopener">Matt Smith: CSS fix for 100vh in mobile WebKit</a></li>
		<li><a href="https://caniuse.com/#feat=intrinsic-width" target="_blank" rel="noopener">Can I use… Intrinsic & Extrinsic Sizing</a></li>
		<li><a href="https://github.com/w3c/csswg-drafts/commit/c372e95e1438308623941bb28ef0f5e7e31dffb3" target="_blank" rel="noopener">GitHub: w3c/csswg-drafts: [css-sizing] Rename fill-available sizing to stretch-fit sizing</a></li>
		<li><a href="https://www.w3.org/TR/css-sizing-3/#stretch-fit" target="_blank" rel="noopener">W3C: CSS Intrinsic & Extrinsic Sizing Module Level 3: Terminology: stretch fit</a></li>
	</ul>
</div>

              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

body {
	margin: 0;
	line-height: 1.4;
	tab-size: 4;
}

pre {
	border: 1px solid #00f;
	padding: 1rem;
	background: white;
	overflow: auto;
	-webkit-overflow-scroll: touch;
}

/* Use standard viewport units by default */
.hero {
	min-height: 100vh;
	padding: 1rem 0;
	background-color: white;
	background-image: linear-gradient(to bottom, white, #aaf 100vh);
}

/* Only apply fix in iOS Safari */
@supports (-webkit-touch-callout: none) {
	.hero {
		min-height: -webkit-fill-available;
		/* Prevent margin/border/padding from shrinking available space */
		box-sizing: content-box;
	}
}

.hero h1 {
	margin: 0;
}

.hero li {
	margin: 1rem 0;
}

.container {
	display: block;
	width: 100%;
	margin: 0 auto;
	max-width: 42rem;
	padding-left: 1rem;
	padding-right: 1rem;
}

.comment {
	color: #999;
}

              
            
!

JS

              
                
              
            
!
999px

Console