網站導覽

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> 或一段標記。內容會填滿邊框內的機身區域,圖片則會裁切至該區域。螢幕的圓角半徑等於機身的圓角半徑減去邊框寬度,因此兩者之間的間距在轉角處也維持一致。

使用標記製作螢幕時,內容從相機凹槽下方開始。請在頂端留出約機身寬度六分之一的空間,就像手機的狀態列一樣。

以標記製作螢幕

<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,元素也在左右各多留 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;    }  }}