結構
展開文字
長文先顯示開頭幾行,使用者可展開閱讀全文。
本頁內容
展開文字元件先顯示長文的前幾行,使用者可視需要展開其餘內容,適合用於說明、評論或變更紀錄。收合時,文字底部會淡出。展開到完整高度時,下方的切換按鈕會翻轉。
展開文字
<details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary class="expand-toggle"> <span class="expand-more">Show more</span><span class="expand-less">Show less</span><svg class="icon expand-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /> </svg> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details>import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'<details className="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary className="expand-toggle"> <span className="expand-more">Show more</span><span className="expand-less">Show less</span><ChevronDownIcon className="icon expand-chevron" /> </summary> <p className="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script> import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary class="expand-toggle"> <span class="expand-more">Show more</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script setup>import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'</script><template> <details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body"> <summary class="expand-toggle"> <span class="expand-more">Show more</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p> </details></template>元件採用原生 <details>,以 <summary> 作為切換按鈕,其中放置按鈕文字和 expand-chevron 圖示,因此支援鍵盤操作、在頁面中尋找及輔助科技。在支援 ::details-content 的瀏覽器中,收合時會顯示預覽。其他瀏覽器會依照原生詳細資料元件的行為,在收合時隱藏內文,仍可透過切換按鈕展開。
依照 <details> 的要求,摘要在標記中必須排在最前面,畫面上則會顯示在文字下方。
#行數
--expand-lines 設定預覽要顯示幾行,高度以內文自身的行高計算。預設為四行。
行數
<details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style="--expand-lines: 2"> <summary class="expand-toggle"> <span class="expand-more">Read the full note</span><span class="expand-less">Show less</span><svg class="icon expand-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /> </svg> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details>import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'<details className="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style={{ '--expand-lines': '2' } as React.CSSProperties}> <summary className="expand-toggle"> <span className="expand-more">Read the full note</span><span className="expand-less">Show less</span><ChevronDownIcon className="icon expand-chevron" /> </summary> <p className="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script> import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style="--expand-lines: 2"> <summary class="expand-toggle"> <span class="expand-more">Read the full note</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p></details><script setup>import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'</script><template> <details class="expand max-w(420) mx-auto text-sm leading-md fg-text-body" style="--expand-lines: 2"> <summary class="expand-toggle"> <span class="expand-more">Read the full note</span><span class="expand-less">Show less</span><ChevronDownIcon class="icon expand-chevron" /> </summary> <p class="m(0)"> Moonstone is a feldspar with a soft glow that seems to move under its surface as the stone turns. The effect comes from light scattering between thin layers inside it. Cut as a smooth dome, it shows a band of light that glides across the top. The theme takes its name from that glow: surfaces are pale and even, edges are found by a line of light before a line of ink, and nothing ends in a hard corner. Obsidian is its counterpart, a volcanic glass, dark and smooth, with edges that catch the light. </p> </details></template>#切換按鈕文案
將兩種狀態的文案分別放進 expand-more 和 expand-less,樣式表會依狀態顯示對應的文字。盡量說清楚展開後能看到什麼,例如「閱讀完整評論」。避免只寫「更多」。如果同一句文案適用於兩種狀態,直接在摘要中填入純文字即可。
#使用時機
多數讀者只會快速掃過的長文,適合使用展開文字元件。問答清單則適合用折疊面板,每一列收合時只顯示標題。請勿將連結和控制項放在隱藏區域。即使內容已收合,仍可透過鍵盤將焦點移到預覽裁切掉的部分。
#無障礙
- 摘要會以按鈕的身分向輔助科技回報文字是否已展開。使用「在頁面中尋找」時,若比對結果在收合內容中,瀏覽器會自動展開。
- 底部的淡出效果由文字遮罩產生,會淡化最後一行可見的文字,前幾行則維持完整對比。
- 啟用減少動態效果時,文字會立即展開。
#類別
| 類別 | 說明 |
|---|---|
expand | details 元素。收合時顯示預覽,預覽在底部逐漸淡出 |
expand-toggle | summary 在標記中排在最前面,畫面上則顯示於文字下方,並搭配會翻轉的 V 形箭頭。 |
expand-chevron | 切換控制項內、位於其文字後方的箭頭圖示,文字展開時翻轉 |
expand-more | 收合時的切換控制項文字 |
expand-less | 展開時的切換控制項文字 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--expand-lines | 4 | 預覽高度,以文字本身的行高為單位 |