aboutsummaryrefslogtreecommitdiff
path: root/build/dv
diff options
context:
space:
mode:
Diffstat (limited to 'build/dv')
-rw-r--r--build/dv/index.html69
1 files changed, 69 insertions, 0 deletions
diff --git a/build/dv/index.html b/build/dv/index.html
new file mode 100644
index 0000000..a8554be
--- /dev/null
+++ b/build/dv/index.html
@@ -0,0 +1,69 @@
+<!doctype html>
+<html lang="en" id="top">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="data:,">
+ <title>Dynamic Viewports with CSS</title>
+ <link href="https://bt.ht/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
+ <style>*{box-sizing:border-box;}body{font-family:sans-serif;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{overflow:auto;}table{text-align:left;width:100%;}</style>
+</head>
+
+<nav>
+ <a href="#menu">Menu &darr;</a>
+</nav>
+
+<main>
+<h1>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>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> &amp; <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>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">&uarr; 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> &amp; <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