diff options
author | Bradley Taunt <bt@btxx.org> | 2024-06-10 09:41:25 -0400 |
---|---|---|
committer | Bradley Taunt <bt@btxx.org> | 2024-06-10 09:41:25 -0400 |
commit | 07e4a2dafe248280b5610f8c7d09b0f30b530f54 (patch) | |
tree | 8a145d1d4d07e1278a837ff15dadccc322d27515 /build/posts/dv/index.html | |
parent | 16d28628aca9b2d356de31c319f5e7bc0f5b2b02 (diff) |
Initial modifications to rebuilt only changed files based on mod date, performance updates
Diffstat (limited to 'build/posts/dv/index.html')
-rw-r--r-- | build/posts/dv/index.html | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/build/posts/dv/index.html b/build/posts/dv/index.html new file mode 100644 index 0000000..43d3cc9 --- /dev/null +++ b/build/posts/dv/index.html @@ -0,0 +1,72 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta name="color-scheme" content="dark light"> + <link rel="icon" href="data:,"> + <title>Dynamic Viewports with CSS</title> + <link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" /> + <link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" /> +<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{background:rgba(0,0,0,0.1);border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style> +</head> + +<nav> + <a href="#menu">Menu ↓</a> +</nav> + +<main> +<h1 id="dynamic-viewports-with-css">Dynamic Viewports with CSS</h1> +<p>2023-02-08</p> +<p>I think it’s safe to assume most web designers and developers are familiar with the standard <code>vh</code> and <code>vw</code> parameters in CSS. These parameters are used for setting an element’s height and/or width, relative to the viewport (v) height (h) or width (w). For example:</p> +<p>If I want my <code>.box</code> element to take up the entire height of a device’s screen:</p> +<pre><code>.box { + height: 100vh; +} +</code></pre> +<p>Or I want my <code>.box</code> element to take up the entire width of a device’s screen:</p> +<pre><code>.box { + width: 100vw; +} +</code></pre> +<p>These are wonderful options to have - specifically for those of us designing web applications. But there are some <em>minor</em> issues with <code>vh</code> and <code>vw</code>.</p> +<ol> +<li>The setting does not take into account device-specific UI (status bars, toolbars, search fields etc.)</li> +<li>In some instances these will not play nice with <code>box-sizing</code> properties</li> +</ol> +<h2 id="have-no-fear-dynamic-viewport-is-here">Have No Fear, Dynamic Viewport is Here!</h2> +<p>Lucky for us there exists an awesome <em>new-ish</em> CSS API called dynamic viewport-percentage units: <code>dvh</code> & <code>dvw</code>. They are defined as follows:</p> +<blockquote> +<p>The dynamic viewport-percentage units (dv) are defined with respect to the dynamic viewport size: the viewport sized with dynamic consideration of any UA interfaces that are dynamically expanded and retracted. This allows authors to size content such that it can exactly fit within the viewport whether or not such interfaces are present.</p> +</blockquote> +<p>So our examples above would translate into:</p> +<pre><code>.box { + height: 100dvh; + width: 100dvw; +} +</code></pre> +<h3 id="what-about-browser-support">What About Browser Support?</h3> +<p><a href="https://caniuse.com/mdn-api_css_dvh">Can I Use Stats</a> / ~67.17% coverage.</p> +<p><strong>Note:</strong> Even though the caniuse page states that Firefox 109+ and iOS Safari 16.3 do not support <code>dvh</code>, in my experiments they do. I’m not sure what testing was done for those two browsers, so YMMV.</p> +<p>If you want to play it safe, use dynamic viewports with standard “traditional” viewports as backup. That way you support all use cases while still taking advantage of newer CSS properties.</p> +<footer role="contentinfo"> + <h2>Menu Navigation</h2> + <ul id="menu"> + <li><a href="/">Home</a></li> + <li><a href="/projects">Projects</a></li> + <li><a href="/uses">Uses</a></li> + <li><a href="/wiki">Wiki</a></li> + <li><a href="/resume">Resume</a></li> + <li><a href="/colophon">Colophon</a></li> + <li><a href="/now">Now</a></li> + <li><a href="/donate">Donate</a></li> + <li><a href="/atom.xml">RSS</a></li> + <li><a href="#top">↑ Top of the page</a></li> + </ul> + <small> + Built with <a href="https://git.sr.ht/~bt/barf">barf</a>. <br> + Maintained with ♥ for the web. <br> + Proud supporter of <a href="https://usefathom.com/ref/DKHJVX">Fathom</a> & <a href="https://nextdns.io/?from=74d3p3h8">NextDNS</a>. <br> + The content for this site is <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>.<br> The <a href="https://git.sr.ht/~bt/bt.ht">code for this site</a> is <a href="https://git.sr.ht/~bt/bt.ht/tree/master/item/LICENSE">MIT</a>. + </small> +</footer>
\ No newline at end of file |