媒體
圖文
呈現搭配圖說的圖片或影片,並修飾媒體邊緣。
本頁內容
圖文元件將圖片、影片或插圖與圖說放在一起。媒體沿用介面容器的圓角,並在邊緣內側加一圈細線,讓淺色圖片和頁面有所區隔,也讓深色圖片的邊緣更柔和。圖說以低調的樣式緊接在媒體下方。若讀者可能想放大圖片查看,可讓圖片在燈箱中開啟。
圖文
<figure class="figure max-w(360) mx-auto"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 3 / 2"> <figcaption class="figure-caption"> Moonstone under a north light, the stone the light theme is named for. </figcaption></figure><figure className="figure max-w(360) mx-auto"> <img className="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style={{ '--figure-ratio': '3 / 2' } as React.CSSProperties} /> <figcaption className="figure-caption"> Moonstone under a north light, the stone the light theme is named for. </figcaption></figure><figure class="figure max-w(360) mx-auto"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 3 / 2"> <figcaption class="figure-caption"> Moonstone under a north light, the stone the light theme is named for. </figcaption></figure><template> <figure class="figure max-w(360) mx-auto"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 3 / 2"> <figcaption class="figure-caption"> Moonstone under a north light, the stone the light theme is named for. </figcaption> </figure></template>在媒體上設定 --figure-ratio,就能在載入前保留指定的長寬比例。載入後,媒體會覆蓋整個區域。省略此設定時,媒體會維持原本的比例。兩種情況都請將 width 和 height 寫在 <img> 上,讓瀏覽器預留空間。
#加框
figure-framed 將媒體放入留有 4px 內距的外框,像照片放在裱框的襯紙上,圖說也會移入框內。外框的圓角半徑是媒體的圓角半徑加上這段內距,因此轉角處的間距也能維持一致。
加框
<figure class="figure figure-framed max-w(360) mx-auto"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 16 / 9"> <figcaption class="figure-caption">Figure 2. The same stone, framed.</figcaption></figure><figure className="figure figure-framed max-w(360) mx-auto"> <img className="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style={{ '--figure-ratio': '16 / 9' } as React.CSSProperties} /> <figcaption className="figure-caption">Figure 2. The same stone, framed.</figcaption></figure><figure class="figure figure-framed max-w(360) mx-auto"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 16 / 9"> <figcaption class="figure-caption">Figure 2. The same stone, framed.</figcaption></figure><template> <figure class="figure figure-framed max-w(360) mx-auto"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 16 / 9"> <figcaption class="figure-caption">Figure 2. The same stone, framed.</figcaption> </figure></template>#置中
figure-center 將圖說置中,並讓各行長度更均衡,適合單獨放在一欄文字中的圖文元件。
置中
<figure class="figure figure-center max-w(240) mx-auto"> <img class="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style="--figure-ratio: 1"> <figcaption class="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption></figure><figure className="figure figure-center max-w(240) mx-auto"> <img className="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style={{ '--figure-ratio': '1' } as React.CSSProperties} /> <figcaption className="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption></figure><figure class="figure figure-center max-w(240) mx-auto"> <img class="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style="--figure-ratio: 1"> <figcaption class="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption></figure><template> <figure class="figure figure-center max-w(240) mx-auto"> <img class="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style="--figure-ratio: 1"> <figcaption class="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption> </figure></template>#無障礙
- 將
<figure>搭配<figcaption>使用,讓圖說成為圖文元件的無障礙名稱。 - 即使已有圖說,仍須保留
alt屬性。替代文字描述圖片呈現的內容,圖說則說明圖片放在這裡的原因。若圖說已涵蓋所有資訊,可用空的alt=""避免重複朗讀。 - 媒體邊緣內側的細線是裝飾,會隨色彩配置變化。在強制色彩模式下,加框的圖文元件會以系統色繪製輪廓線。
#類別
| 類別 | 說明 |
|---|---|
figure | 圖文區塊,媒體在上,說明文字在下 |
figure-framed | 媒體在外框內縮 4px,說明文字也位於框內。搭配 figure 使用 |
figure-center | 置中且各行長度均衡的圖說,適用於正文欄中獨立呈現的圖文區塊。搭配 figure 使用 |
figure-media | 可使用 img、video、svg 或任何區塊,沿用表面的圓角,並在邊緣內側繪製細線外框 |
figure-caption | 媒體下方的說明文字,使用較小的字級與較柔和的文字色。 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--figure-radius | var(--radius-surface) | 媒體的圓角半徑。 |
--figure-ratio | 媒體載入前會依指定的長寬比保留空間,載入後會填滿該區域。未指定時,媒體會維持原有的長寬比。設定於 figure-media |