跳到內容

螢幕截圖

Screenshot 元件能渲染具主題感知能力的圖片,當使用者切換網站主題時,會自動在淺色與深色變體之間切換。每當您需要顯示 UI 截圖,且希望截圖符合讀者目前的配色方案時,請使用此元件。

屬性類型必填說明
lightstring淺色模式圖片路徑
darkstring深色模式圖片路徑
altstring無障礙替代文字
widthnumber圖片寬度(像素)
heightnumber圖片高度(像素)

同時提供 lightdark 屬性,以在每種主題下顯示對應的變體。 切換右上角的主題選擇器,即可觀察圖片切換效果。

Docs theme homepageDocs theme homepage
import Screenshot from '@f5-sales-demo/docs-theme/components/Screenshot.astro';
<Screenshot
light="/images/screenshot-example-light.png"
dark="/images/screenshot-example-dark.png"
alt="Docs theme homepage"
/>

當只有一種變體可用時,僅傳入 lightdark 其中之一。 該圖片將在兩種主題下均正常渲染,不會進行切換。

Docs theme homepage (dark only)
<Screenshot
dark="/images/screenshot-example-dark.png"
alt="Docs theme homepage (dark only)"
/>

使用 widthheight 控制渲染尺寸,並避免版面位移。

Docs theme homepage at fixed widthDocs theme homepage at fixed width
<Screenshot
light="/images/screenshot-example-light.png"
dark="/images/screenshot-example-dark.png"
alt="Docs theme homepage at fixed width"
width={600}
height={338}
/>

此元件會在 .screenshot-pair 包裝元素內渲染一個或兩個 <img> 元素。CSS 規則會依據目前啟用的主題切換可見性:

  • 深色模式(預設)— .screenshot-light 圖片透過 :root:not([data-theme="light"]) .screenshot-light \{ display: none \} 隱藏
  • 淺色模式.screenshot-dark 圖片透過 :root[data-theme="light"] .screenshot-dark \{ display: none \} 隱藏

額外的選擇器透過 :has() 處理 starlight-image-zoom 包裝元素, 確保縮放功能在兩種變體下均能正常運作。

所有截圖圖片皆套用一致的樣式:細緻的邊框、圓角,以及滑鼠懸停時加深的陰影效果。

功能Screenshot 元件Markdown ![](url)
主題感知切換支援不支援
樣式邊框與陰影自動套用不支援
懸停陰影效果支援不支援
縮放支援與圖片縮放外掛相容與圖片縮放外掛相容
替代文字alt 屬性![alt text]()

當您擁有主題專屬的圖片變體,或希望呈現具樣式的截圖外觀時,請使用 Screenshot 元件。若為行內圖形、示意圖,或在兩種主題下外觀相同的圖片,則使用標準 Markdown 圖片語法即可。