大网数据广告活动
Web 标准与前端开发

`vertical-viewport-segments` CSS media feature

· 52CE 我爱测

The **`vertical-viewport-segments`** CSS media feature detects whether the device has a specified number of viewport segments laid out vertically (top to bottom).

The vertical-viewport-segments CSS media feature detects whether the device has a specified number of viewport segments laid out vertically (top to bottom).

Related to the Viewport Segments API, the vertical-viewport-segments feature can be used to create responsive designs that work well on multi-viewport devices — devices with a display that is divided into logically separate viewport segments, such as foldable or hinged devices.

Syntax

The vertical-viewport-segments feature is specified as an integer value of 1 or greater, representing the number of vertical viewport segments the device has.

  • The value will be 1 for:
    • A non-foldable device (for example, a standard single-screen smartphone or tablet).
    • A foldable device that is either unfolded or closed (in the continuous device posture).
    • A two-screen hinged device or a foldable device that is currently folded and is oriented horizontally so the segments are side by side.
  • The value will be 2 for a two-screen hinged device or a foldable device that is currently folded (in the folded device posture) and is oriented vertically so the segments are on top of one another.
  • The value may be greater than 2 for foldable devices with more than one fold.

Examples

Basic vertical-viewport-segments usage

In this snippet we use a vertical-viewport-segments media query to handle the case of foldable devices where the segments are top-to-bottom.

We set the top container to have a height equal to the top segment height (env(viewport-segment-height 0 0)), and the bottom container to have a height equal to the bottom segment height (env(viewport-segment-height 0 1)).

To calculate how much height the fold takes up in between the two, we subtract the bottom edge offset of the top container from the top edge offset of the bottom container (calc(env(viewport-segment-top 0 1) - env(viewport-segment-bottom 0 0));).

.wrapper {
  height: 100%;
  display: flex;
}

@media (vertical-viewport-segments: 2) {
  .wrapper {
    flex-direction: column;
  }

  .list-view {
    height: env(viewport-segment-height 0 0);
  }

  .fold {
    width: 100%;
    height: calc(
      env(viewport-segment-top 0 1) - env(viewport-segment-bottom 0 0)
    );
    background-color: black;
  }

  .detail-view {
    height: env(viewport-segment-height 0 1);
  }
}

See our Viewport segment API demo for a full working demo (source code). Also check out Using the Viewport Segments API for a full demo explanation.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。