網站導覽

v2.1.0
媒體

視窗

為螢幕擷取畫面、示範或終端機加上應用程式視窗外框。

本頁內容

視窗以應用程式外框呈現你想展示的內容,例如螢幕擷取畫面、簡短示範或幾行終端機輸出。視窗面板略微浮起,頂列橫跨整個視窗。頂列上的三個標記採用與框線相同的無彩色,讓人一眼認出這是視窗,也讓內容本身的色彩成為焦點。

視窗

<figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">Atlas · Deployments</span>  </div>  <img class="window-body object-cover w-full" style="aspect-ratio: 16 / 10" src="/demo/moonstone.svg" alt="The deployments view of Atlas"></figure>
<figure className="window max-w(520) mx-auto">  <div className="window-bar">    <span className="window-controls" aria-hidden="true"></span>    <span className="window-title">Atlas · Deployments</span>  </div>  <img className="window-body object-cover w-full" style={{ aspectRatio: '16 / 10' }} src="/demo/moonstone.svg" alt="The deployments view of Atlas" /></figure>
<figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">Atlas · Deployments</span>  </div>  <img class="window-body object-cover w-full" style="aspect-ratio: 16 / 10" src="/demo/moonstone.svg" alt="The deployments view of Atlas"></figure>
<template>  <figure class="window max-w(520) mx-auto">    <div class="window-bar">      <span class="window-controls" aria-hidden="true"></span>      <span class="window-title">Atlas · Deployments</span>    </div>    <img class="window-body object-cover w-full" style="aspect-ratio: 16 / 10" src="/demo/moonstone.svg" alt="The deployments view of Atlas">  </figure></template>

#頂列

window-bar 分為三個區域。起始端放置 window-controls,它是一個呈現為三個實心圓的空元素。中央可放 window-title 或 window-address,後者是帶有內凹效果的網址欄,類似瀏覽器的網址列。window-end 用來容納尾端的內容。各區域都可省略,中央區域會維持置中,不受兩側內容影響。

網址

<figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-address">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="3" y="7" width="10" height="7" rx="1" /><path d="M5.5 7V4.5A2.5 2.5 0 0 1 10.5 4.5V7" /><path d="M8 9.5L8 11" />      </svg>atlas.dev/deployments    </span>    <span class="window-end"><span class="badge badge-sm badge-success badge-dot">Live</span></span>  </div>  <div class="window-body flex flex-col gap-sm p-lg">    <div class="skeleton skeleton-text w(180)"></div>    <div class="skeleton skeleton-text"></div>    <div class="skeleton skeleton-text w(320)"></div>    <div class="skeleton h(96) mt-xs"></div>  </div></figure>
import LockIcon from '@master/icons-react/native/16/soft/lock'<figure className="window max-w(520) mx-auto">  <div className="window-bar">    <span className="window-controls" aria-hidden="true"></span>    <span className="window-address"><LockIcon className="icon" />atlas.dev/deployments</span>    <span className="window-end">      <span className="badge badge-sm badge-success badge-dot">Live</span>    </span>  </div>  <div className="window-body flex flex-col gap-sm p-lg">    <div className="skeleton skeleton-text w(180)"></div>    <div className="skeleton skeleton-text"></div>    <div className="skeleton skeleton-text w(320)"></div>    <div className="skeleton h(96) mt-xs"></div>  </div></figure>
<script>  import LockIcon from '@master/icons-svelte/native/16/soft/lock'</script><figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-address"><LockIcon class="icon" />atlas.dev/deployments</span>    <span class="window-end"><span class="badge badge-sm badge-success badge-dot">Live</span></span>  </div>  <div class="window-body flex flex-col gap-sm p-lg">    <div class="skeleton skeleton-text w(180)"></div>    <div class="skeleton skeleton-text"></div>    <div class="skeleton skeleton-text w(320)"></div>    <div class="skeleton h(96) mt-xs"></div>  </div></figure>
<script setup>import LockIcon from '@master/icons-vue/native/16/soft/lock'</script><template>  <figure class="window max-w(520) mx-auto">    <div class="window-bar">      <span class="window-controls" aria-hidden="true"></span>      <span class="window-address"><LockIcon class="icon" />atlas.dev/deployments</span>      <span class="window-end">        <span class="badge badge-sm badge-success badge-dot">Live</span>      </span>    </div>    <div class="window-body flex flex-col gap-sm p-lg">      <div class="skeleton skeleton-text w(180)"></div>      <div class="skeleton skeleton-text"></div>      <div class="skeleton skeleton-text w(320)"></div>      <div class="skeleton h(96) mt-xs"></div>    </div>  </figure></template>

#內容區

window-body 沒有內距,讓圖片或影片貼齊外框,並由視窗的圓角裁切。若要留出文字周圍的空間,請使用設定內距的工具類別。請將這個類別加在內容元素本身,例如 <img>、<video>、<pre> 或 <div>。

window-flat 保留一道外框並移除陰影,適合放在容器內,或與其他內容一起放在版面密集的頁面上。

終端機

<figure class="window window-flat max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">zsh</span>  </div>  <pre class="window-body p-md font-mono text-xs leading-lg fg-text-strong overflow-x-auto"><span class="fg-text-muted">$</span> npm install @master/css @master/ui<span class="fg-text-muted">added 2 packages in 1.4s</span><span class="fg-text-muted">$</span> npm run dev</pre></figure>
<figure class="window window-flat max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">zsh</span>  </div>  <pre class="window-body p-md font-mono text-xs leading-lg fg-text-strong overflow-x-auto"><span class="fg-text-muted">$</span> npm install @master/css @master/ui<span class="fg-text-muted">added 2 packages in 1.4s</span><span class="fg-text-muted">$</span> npm run dev</pre></figure>
<template>  <figure class="window window-flat max-w(520) mx-auto">    <div class="window-bar">      <span class="window-controls" aria-hidden="true"></span>      <span class="window-title">zsh</span>    </div>    <pre class="window-body p-md font-mono text-xs leading-lg fg-text-strong overflow-x-auto"><span class="fg-text-muted">$</span> npm install @master/css @master/ui<span class="fg-text-muted">added 2 packages in 1.4s</span><span class="fg-text-muted">$</span> npm run dev</pre>  </figure></template>

#無障礙

  • 外框僅供裝飾。請用 aria-hidden="true" 隱藏 window-controls,這些圓點只是裝飾,不具按鈕功能。
  • 如果視窗用來輔助說明周圍的文字,可以使用 <figure>。若畫面需要解說,請在該元素內的視窗內容後加上 <figcaption>。
  • 請在 alt 中描述螢幕擷取畫面。頂列標題是畫面的一部分,無法取代替代文字。
  • 請勿用視窗元件製作可操作的對話框。若需要在頁面上方開啟對話框,請使用 dialog。

#類別

類別說明
window外框略帶立體感,圓角為 12px,並裁切超出的內容
window-flat使用單一道外框,適合托盤上或版面緊湊頁面中的視窗。無陰影。搭配 window 使用
window-bar頂端橫列,起始端放標記,中間放標題或網址,末端預留控制項的位置
window-controls頂端橫列起始端的三個標記由同一個空元素繪製。請使用 aria-hidden="true",讓輔助技術略過該元素
window-title單行標題置於頂端橫列中央
window-address頂端橫列中央改以小型網址框顯示網址
window-end位於頂端橫列末端的內容
window-body視窗顯示的內容,可以是圖片、影片、pre 或 div,內距為 0

#自訂屬性

屬性預設值說明
--window-radiusvar(--radius-control-lg)外框圓角
--window-bar-height2.5rem頂端橫列高度

#原始碼

@master/ui/components/window.css
/* * Window: the frame of an application around a screenshot, a demo or a few lines of a terminal. * A lifted sheet with a 12px corner. Its bar is a quieter tone over a hairline and carries three marks at * the start, drawn from one element in the ink of a line, with no hue: the frame says "this is a window" * and leaves the color to what it shows. A title stands in the middle of the bar, or an address in a small * well. The body is cut by the window's own corner, so a picture runs to the edge. */@layer components.ui {  .window {    --window-radius: var(--radius-control-lg);    --window-bar-height: 2.5rem;    --surface-color: var(--color-surface-raised);    position: relative;    display: flex;    flex-direction: column;    min-width: 0;    margin: 0;    border-radius: calc(var(--window-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    /* The bar's tone and a picture in the body are finished by the window's corner. */    overflow: clip;    background: var(--color-surface-raised);    color: var(--color-text-body);    box-shadow: var(--shadow-lifted);    /* One contour and no lift, for a window on a tray or in a dense page. */    &.window-flat {      box-shadow: var(--shadow-flat);    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* The bar: the marks at the start, the title or the address in the middle, and room for a control at the end. */  .window-bar {    display: grid;    flex: none;    /* The sides never shrink below what they hold, so a long title is cut instead of running under the marks. */    grid-template-columns: minmax(min-content, 1fr) auto minmax(min-content, 1fr);    align-items: center;    gap: .75rem;    min-height: var(--window-bar-height);    padding: 0 .875rem;    border-block-end: 1px solid var(--color-line-hair);    @apply --surface-sheet;    box-shadow: inset 0 1px 0 var(--color-highlight);  }  /* Three marks, 11px each, 8px apart: discs of the line ink with a faint edge of their own. */  .window-controls {    --window-mark: var(--color-line-strong);    display: block;    width: 3.0625rem;    height: .6875rem;    background:      radial-gradient(circle at 5.5px 50%, var(--window-mark) 5px, transparent 5.5px),      radial-gradient(circle at 24.5px 50%, var(--window-mark) 5px, transparent 5.5px),      radial-gradient(circle at 43.5px 50%, var(--window-mark) 5px, transparent 5.5px);    @media (forced-colors: active) {      --window-mark: CanvasText;      forced-color-adjust: none;    }  }  .window-title {    grid-column: 2;    max-width: 100%;    margin: 0;    overflow: hidden;    color: var(--color-text-muted);    font: var(--font-weight-control) .8125rem/1.2 var(--font-family-sans);    font-feature-settings: inherit;    text-align: center;    text-overflow: ellipsis;    white-space: nowrap;  }  /* An address instead of a title: a small well in the middle of the bar, as a browser has. */  .window-address {    --icon-size: .75rem;    display: inline-flex;    grid-column: 2;    align-items: center;    /* An address longer than the well keeps its start in view and is cut at its end. */    justify-content: safe center;    gap: .375rem;    width: min(100%, 16rem);    min-width: 0;    height: 1.625rem;    padding: 0 .75rem;    border-radius: calc((var(--window-radius) - .25rem) * var(--corner-scale));    corner-shape: var(--corner-shape);    overflow: hidden;    background: var(--color-surface-inset);    color: var(--color-text-muted);    box-shadow: var(--shadow-pressed);    font: 400 .75rem/1 var(--font-family-sans);    font-feature-settings: inherit;    text-overflow: ellipsis;    white-space: nowrap;    /* Shadows are not drawn here, so the well keeps its edge as a rule. */    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* What stands at the end of the bar. */  .window-end {    display: inline-flex;    grid-column: 3;    align-items: center;    justify-content: flex-end;    gap: .25rem;    min-width: 0;    color: var(--color-text-muted);  }  /* What the window shows. It has no padding: a picture or a video meets the frame. */  .window-body {    display: block;    flex: 1 1 auto;    min-width: 0;    min-height: 0;    margin: 0;  }}