docs.rodeo

MDN Web Docs mirror

horizontal-viewport-segments

The horizontal-viewport-segments CSS media feature detects whether the device has a specified number of viewport segments laid out horizontally (side by side).

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 horizontal-viewport-segments feature is specified as an {{cssxref("integer")}}  value of 1 or greater, representing the number of horizontal viewport segments the device has.

Examples

Basic horizontal-viewport-segments usage

In this snippet we use a horizontal-viewport-segments media query to handle the case of foldable devices where the segments are side-by-side.

We set the left container to have a width equal to the left segment width (env(viewport-segment-width 0 0)), and the right container to have a width equal to the right segment width (env(viewport-segment-width 1 0)).

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

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

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

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

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

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

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

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN