ナビゲーション

v2.1.0
メディア

デバイス

スクリーンショット、動画、動作するデモを囲むスマートフォンの筐体です。

このページの内容

デバイスは、スクリーンショット、動画、動作するデモを囲むスマートフォンの筐体です。粘土を型に入れて作った模型のように、一段高くなった板状の本体、細いベゼル、画面上部のカメラ位置にある小さな凹部を、ひとつの素材でできているように描きます。デスクトップ向けのウィンドウと同様に、フレームの形でスマートフォンだと伝え、色はすべて表示するコンテンツに委ねます。

デバイス

<div class="device" style="--device-width: 13.5rem">  <img class="device-screen" src="/demo/moonstone.svg" alt="A pale stone over grey hills"></div>
<div className="device" style={{ '--device-width': '13.5rem' } as React.CSSProperties}>  <img className="device-screen" src="/demo/moonstone.svg" alt="A pale stone over grey hills" /></div>
<div class="device" style="--device-width: 13.5rem">  <img class="device-screen" src="/demo/moonstone.svg" alt="A pale stone over grey hills"></div>
<template>  <div class="device" style="--device-width: 13.5rem">    <img class="device-screen" src="/demo/moonstone.svg" alt="A pale stone over grey hills">  </div></template>

#画面

device-screenは、画面に表示する<img>、<video>、<iframe>、またはマークアップのブロックに指定します。コンテンツはベゼルの内側いっぱいに広がり、画像は画面に合わせて切り抜かれます。画面の角丸の半径は本体の角丸の半径からベゼルの幅を引いた値で、角でも間隔が一定になります。

マークアップで画面を作る場合は、実機のステータスバーと同じように、画面上部に本体幅の約6分の1の余白を取り、カメラ用の凹部より下にコンテンツを配置します。

マークアップで作る画面

<div class="device" style="--device-width: 13.5rem">  <div class="device-screen bg-surface-base flex flex-col gap-sm px(14) pt(44) pb(14)">    <p class="eyebrow">Wednesday</p>    <p class="heading heading-lg">Today</p>    <ul class="checklist mt(4)">      <li class="checklist-item">        <label class="checklist-label">          <input class="checkbox" type="checkbox" checked><span class="checklist-title">Review the contract</span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input class="checkbox" type="checkbox"><span class="checklist-title">Call Grace at three</span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input class="checkbox" type="checkbox"><span class="checklist-title">Book the flight</span>        </label>      </li>    </ul>  </div></div>
<div className="device" style={{ '--device-width': '13.5rem' } as React.CSSProperties}>  <div className="device-screen bg-surface-base flex flex-col gap-sm px(14) pt(44) pb(14)">    <p className="eyebrow">Wednesday</p>    <p className="heading heading-lg">Today</p>    <ul className="checklist mt(4)">      <li className="checklist-item">        <label className="checklist-label">          <input className="checkbox" type="checkbox" defaultChecked /><span className="checklist-title">Review the contract</span>        </label>      </li>      <li className="checklist-item">        <label className="checklist-label">          <input className="checkbox" type="checkbox" /><span className="checklist-title">Call Grace at three</span>        </label>      </li>      <li className="checklist-item">        <label className="checklist-label">          <input className="checkbox" type="checkbox" /><span className="checklist-title">Book the flight</span>        </label>      </li>    </ul>  </div></div>
<div class="device" style="--device-width: 13.5rem">  <div class="device-screen bg-surface-base flex flex-col gap-sm px(14) pt(44) pb(14)">    <p class="eyebrow">Wednesday</p>    <p class="heading heading-lg">Today</p>    <ul class="checklist mt(4)">      <li class="checklist-item">        <label class="checklist-label">          <input class="checkbox" type="checkbox" checked><span class="checklist-title">Review the contract</span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input class="checkbox" type="checkbox"><span class="checklist-title">Call Grace at three</span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input class="checkbox" type="checkbox"><span class="checklist-title">Book the flight</span>        </label>      </li>    </ul>  </div></div>
<template>  <div class="device" style="--device-width: 13.5rem">    <div class="device-screen bg-surface-base flex flex-col gap-sm px(14) pt(44) pb(14)">      <p class="eyebrow">Wednesday</p>      <p class="heading heading-lg">Today</p>      <ul class="checklist mt(4)">        <li class="checklist-item">          <label class="checklist-label">            <input class="checkbox" type="checkbox" checked><span class="checklist-title">Review the contract</span>          </label>        </li>        <li class="checklist-item">          <label class="checklist-label">            <input class="checkbox" type="checkbox"><span class="checklist-title">Call Grace at three</span>          </label>        </li>        <li class="checklist-item">          <label class="checklist-label">            <input class="checkbox" type="checkbox"><span class="checklist-title">Book the flight</span>          </label>        </li>      </ul>    </div>  </div></template>

#サイズ

本体の既定幅は280pxで、幅と高さの比率は9:19.5です。サイズ変更には幅の直接指定ではなく、--device-widthを使います。角丸の半径はその値の14%、ベゼルの幅は3%なので、サイズを変えても形状が保たれます。旧型のスマートフォンや小型タブレットを表現するには、--device-ratioで縦横比を変えます。側面ボタンは本体から2px突き出し、要素の幅にはその分が左右に含まれるため、スクロール領域の端に置いてもスクロール範囲は広がりません。

サイズのバリエーション

<div class="device" style="--device-width: 7rem">  <img class="device-screen" src="/demo/moonstone.svg" alt></div><div class="device" style="--device-width: 9rem">  <img class="device-screen" src="/demo/moonstone.svg" alt></div><div class="device" style="--device-width: 11rem; --device-ratio: 3 / 4">  <img class="device-screen" src="/demo/moonstone.svg" alt></div>
<>  <div className="device" style={{ '--device-width': '7rem' } as React.CSSProperties}>    <img className="device-screen" src="/demo/moonstone.svg" alt="" />  </div>  <div className="device" style={{ '--device-width': '9rem' } as React.CSSProperties}>    <img className="device-screen" src="/demo/moonstone.svg" alt="" />  </div>  <div className="device" style={{ '--device-width': '11rem', '--device-ratio': '3 / 4' } as React.CSSProperties}>    <img className="device-screen" src="/demo/moonstone.svg" alt="" />  </div></>
<div class="device" style="--device-width: 7rem">  <img class="device-screen" src="/demo/moonstone.svg" alt></div><div class="device" style="--device-width: 9rem">  <img class="device-screen" src="/demo/moonstone.svg" alt></div><div class="device" style="--device-width: 11rem; --device-ratio: 3 / 4">  <img class="device-screen" src="/demo/moonstone.svg" alt></div>
<template>  <div class="device" style="--device-width: 7rem">    <img class="device-screen" src="/demo/moonstone.svg" alt>  </div>  <div class="device" style="--device-width: 9rem">    <img class="device-screen" src="/demo/moonstone.svg" alt>  </div>  <div class="device" style="--device-width: 11rem; --device-ratio: 3 / 4">    <img class="device-screen" src="/demo/moonstone.svg" alt>  </div></template>

#アクセシビリティ

  • フレームは装飾なので読み上げられません。画面に意味があるため、画像には表示されているインターフェースの内容を伝えるaltを指定します。隣のテキストですでに説明している場合は、空のaltを指定します。
  • 画面内で動作するデモは、小さな実際のページです。操作対象はタッチ操作に十分な大きさを確保し、キーボードで操作できるようにするか、キーボード操作の対象から外します。
  • 強制カラーモードでは、本体とカメラ用の凹部にシステムカラーのアウトラインが付きます。
  • 画面内で自動再生する録画は音声なしにします。音声や操作の手順で内容を伝える録画には、キャプションやテキストによる説明も必要です。

#クラス

クラス説明
device筐体は幅 280px、幅と高さの比が 9 対 19.5 の浮き上がったシートで、細いベゼル、カメラのくぼみ、側面ボタンを備えます。ボタンは筐体から 2px 突き出しますが、要素自体のボックス内に収まり、ボックスの外側には何も描画されません。
device-screen画像、動画、フレーム、またはマークアップのブロックに適用します。画面はベゼルの内側いっぱいに広がり、画面と筐体の角丸は中心を共有します。

#カスタムプロパティ

プロパティ既定値説明
--device-width17.5rem筐体の幅。角丸とベゼルの寸法はこの幅を基準に算出
--device-ratio9 / 19.5筐体の縦横比
--device-radiuscalc(var(--device-width) * .14)筐体の角を円弧で丸める半径
--device-bezelcalc(var(--device-width) * .03)画面を囲む枠の幅

#ソース

@master/ui/components/device.css
/* * Device: the body of a phone around a screenshot, a video or a running demo. * It is drawn in one material, like a model cast in clay: a lifted sheet for the body, a narrow bezel, and * a small well at the top of the screen where the camera would be. The frame says "this is a phone" and * leaves every color to what it shows, as a window does. * Everything is measured from the body's width: the corner is 14% of it, the bezel 3% and the screen's own * corner is the body's minus the bezel, so the gap keeps one width around the bend. The body is 280px wide * and 9 by 19.5; set --device-width to resize it, not a width, so the corners follow. * The side buttons stand 2px proud of the body, and the element is that much wider than the body on each * side to hold them: nothing is drawn outside its box, so a device at the edge of a scroller adds no scroll. */@layer components.ui {  .device {    --device-width: 17.5rem;    --device-ratio: 9 / 19.5;    --device-radius: calc(var(--device-width) * .14);    --device-bezel: calc(var(--device-width) * .03);    --device-button: 2px;    --surface-color: var(--color-surface-raised);    position: relative;    display: block;    flex: none;    box-sizing: border-box;    /* The body and the camera's well are layers of the device, and no further back or forward than that. */    isolation: isolate;    width: calc(var(--device-width) + var(--device-button) * 2);    height: calc(var(--device-width) / (var(--device-ratio)));    margin: 0;    padding: var(--device-bezel) calc(var(--device-bezel) + var(--device-button));    /* The buttons: three on one side and one on the other, as thin slips the body covers all but 2px of. */    background:      linear-gradient(var(--color-line-strong) 0 0) 0 17% / 50% 4% no-repeat,      linear-gradient(var(--color-line-strong) 0 0) 0 26% / 50% 8% no-repeat,      linear-gradient(var(--color-line-strong) 0 0) 0 37% / 50% 8% no-repeat,      linear-gradient(var(--color-line-strong) 0 0) 100% 31% / 50% 13% no-repeat;    /* The body: a lifted sheet behind the screen. A hairline inside its edge turns the sheet into a frame with a rim. */    &::before {      content: '';      position: absolute;      z-index: -1;      inset: 0 var(--device-button);      border-radius: calc(var(--device-radius) * var(--corner-scale));      corner-shape: var(--corner-shape);      @apply --surface-sheet;      box-shadow: inset 0 0 0 1px var(--color-line-hair), var(--shadow-lifted);      pointer-events: none;    }    /* The camera's well: a pill a third of the screen wide, a little below its top edge. */    &::after {      content: '';      position: absolute;      z-index: 1;      top: calc(var(--device-bezel) + var(--device-width) * .03);      left: 50%;      width: calc(var(--device-width) * .3);      aspect-ratio: 3.4;      border-radius: 999px;      corner-shape: round;      background: var(--color-surface-raised-low);      box-shadow: var(--shadow-pressed);      translate: -50% 0;      pointer-events: none;    }    @media (forced-colors: active) {      background: none;      &::before, &::after {        outline: 1px solid CanvasText;        outline-offset: -1px;      }    }  }  /* The screen: a picture, a video, a frame or a block of markup, finished by a corner concentric with the body's. */  .device-screen {    display: block;    box-sizing: border-box;    width: 100%;    height: 100%;    margin: 0;    border: 0;    border-radius: calc(var(--device-radius) * var(--corner-scale) - var(--device-bezel));    corner-shape: var(--corner-shape);    overflow: clip;    background: var(--color-surface-inset);    outline: 1px solid var(--color-line-image-strong);    outline-offset: -1px;    object-fit: cover;    @media (forced-colors: active) {      outline-color: CanvasText;    }  }}