From 07e4a2dafe248280b5610f8c7d09b0f30b530f54 Mon Sep 17 00:00:00 2001 From: Bradley Taunt Date: Mon, 10 Jun 2024 09:41:25 -0400 Subject: Initial modifications to rebuilt only changed files based on mod date, performance updates --- build/posts/dv/index.html | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 build/posts/dv/index.html (limited to 'build/posts/dv/index.html') 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 @@ + + + + + + + + Dynamic Viewports with CSS + + + + + + + +
+

Dynamic Viewports with CSS

+

2023-02-08

+

I think it’s safe to assume most web designers and developers are familiar with the standard vh and vw 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:

+

If I want my .box element to take up the entire height of a device’s screen:

+
.box {
+    height: 100vh;
+}
+
+

Or I want my .box element to take up the entire width of a device’s screen:

+
.box {
+    width: 100vw;
+}
+
+

These are wonderful options to have - specifically for those of us designing web applications. But there are some minor issues with vh and vw.

+
    +
  1. The setting does not take into account device-specific UI (status bars, toolbars, search fields etc.)
  2. +
  3. In some instances these will not play nice with box-sizing properties
  4. +
+

Have No Fear, Dynamic Viewport is Here!

+

Lucky for us there exists an awesome new-ish CSS API called dynamic viewport-percentage units: dvh & dvw. They are defined as follows:

+
+

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.

+
+

So our examples above would translate into:

+
.box {
+    height: 100dvh;
+    width: 100dvw;
+}
+
+

What About Browser Support?

+

Can I Use Stats / ~67.17% coverage.

+

Note: Even though the caniuse page states that Firefox 109+ and iOS Safari 16.3 do not support dvh, in my experiments they do. I’m not sure what testing was done for those two browsers, so YMMV.

+

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.

+ \ No newline at end of file -- cgit v1.2.3-54-g00ecf