--- id: 587d778a367417b2b2512aa5 title: 使用 figure 元素提高圖表的可訪問性 challengeType: 0 videoUrl: 'https://scrimba.com/c/cGJMqtE' forumTopicId: 301015 dashedName: improve-chart-accessibility-with-the-figure-element --- # --description-- HTML5 引入了 `figure` 標籤以及與之相關的 `figcaption` 標籤。 它們一起用於展示可視化信息(如:圖片、圖表)及其標題。 這樣通過語義化對內容進行分組並配以用於解釋 `figure` 的文字,可以極大地提升內容的可訪問性。 對於圖表之類的可視化數據,標題可以爲屏幕閱讀器用戶提供簡要的說明。 但是這裏有一個難點,如何爲屏幕閱讀器用戶展示那些超出屏幕可視範圍(使用 CSS)的表格所表現的圖表數據。 舉個例子,注意 `figcaption` 包含在 `figure` 標籤中,並且可以與其他標籤組合使用: ```html
Photo of Camper Cat executing a roundhouse kick
Master Camper Cat demonstrates proper form of a roundhouse kick.
``` # --instructions-- Camper Cat 正在努力創建一張條形圖,用來顯示每週用於隱形、戰鬥、武器訓練的時間。 請幫助完善他的頁面,將他用於呈現圖表的 `div` 標籤修改爲 `figure` 標籤;將用於呈現圖表標題的 `p` 標籤改爲 `figcaption` 標籤。 # --hints-- 應存在一個 `figure` 標籤。 ```js assert($('figure').length == 1); ``` 應存在一個 `figcaption` 標籤。 ```js assert($('figcaption').length == 1); ``` 不應存在 `div` 標籤。 ```js assert($('div').length == 0); ``` 不應存在 `p` 標籤。 ```js assert($('p').length == 0); ``` `figcaption` 應爲 `figure` 的子標籤。 ```js assert($('figure').children('figcaption').length == 1); ``` 確保 `figure` 元素有結束標籤。 ```js assert( code.match(/<\/figure>/g) && code.match(/<\/figure>/g).length === code.match(/
/g).length ); ``` # --seed-- ## --seed-contents-- ```html

Training


Breakdown per week of time to spend training in stealth, combat, and weapons.

Stealth & Agility Training

Climb foliage quickly using a minimum spanning tree approach

No training is NP-complete without parkour

Combat Training

Dispatch multiple enemies with multithreaded tactics

Goodbye world: 5 proven ways to knock out an opponent

Weapons Training

Swords: the best tool to literally divide and conquer

Breadth-first or depth-first in multi-weapon training?

``` # --solutions-- ```html

Training


Breakdown per week of time to spend training in stealth, combat, and weapons.

Stealth & Agility Training

Climb foliage quickly using a minimum spanning tree approach

No training is NP-complete without parkour

Combat Training

Dispatch multiple enemies with multithreaded tactics

Goodbye world: 5 proven ways to knock out an opponent

Weapons Training

Swords: the best tool to literally divide and conquer

Breadth-first or depth-first in multi-weapon training?

```