From dcfb172704f3afb68a30425029ec834be2883274 Mon Sep 17 00:00:00 2001 From: bt Date: Sat, 8 Jun 2024 13:22:19 -0400 Subject: More content porting, on-going markdown changes for lowdown support --- build/dv/index.html | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'build/dv/index.html') diff --git a/build/dv/index.html b/build/dv/index.html index a8554be..4f27bd1 100644 --- a/build/dv/index.html +++ b/build/dv/index.html @@ -1,51 +1,70 @@ - + Dynamic Viewports with CSS - - + + +
-

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:

+ +

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:

+ +

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. In some instances these will not play nice with box-sizing properties
-

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.

+ +

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.

+ +

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.