回饋
定位提示
以外框標出連結指向的位置,隨後淡出。
本頁內容
定位提示用來標示連結指向的位置。將 flash 加到任何具有 ID 的元素上,例如標題、表格列、留言或卡片。當網址片段與該 ID 相符時,元素周圍會出現前景色外框,並在兩秒內淡出,讓讀者一眼找到連結指向的項目。整個效果由網址決定,無須腳本。
定位提示
<div class="card max-w(480) mx-auto"> <p class="m(0) text-sm"> Jump to <a class="link" href="#comment-ada">Ada's comment</a> or <a class="link" href="#comment-grace">Grace's reply</a>. </p> <ol class="thread"> <li class="thread-item flash" id="comment-ada" style="--flash-offset: 1rem"> <span class="thread-avatar"><span class="avatar">AL</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Ada Lovelace</span> <time class="thread-meta" datetime="2026-11-12T09:12">2h</time> </p> <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p> </div> </li> <li class="thread-item flash" id="comment-grace" style="--flash-offset: 1rem"> <span class="thread-avatar"><span class="avatar">GH</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Grace Hopper</span> <time class="thread-meta" datetime="2026-11-12T10:31">35m</time> </p> <p class="thread-text">I will make the change this afternoon.</p> </div> </li> </ol></div><div className="card max-w(480) mx-auto"> <p className="m(0) text-sm"> Jump to <a className="link" href="#comment-ada">Ada's comment</a> or <a className="link" href="#comment-grace">Grace's reply</a>. </p> <ol className="thread"> <li className="thread-item flash" id="comment-ada" style={{ '--flash-offset': '1rem' } as React.CSSProperties}> <span className="thread-avatar"><span className="avatar">AL</span></span> <div className="thread-body"> <p className="thread-header"> <span className="thread-author">Ada Lovelace</span> <time className="thread-meta" dateTime="2026-11-12T09:12">2h</time> </p> <p className="thread-text"> The focus ring is cut by the mask. Should it move to the group? </p> </div> </li> <li className="thread-item flash" id="comment-grace" style={{ '--flash-offset': '1rem' } as React.CSSProperties}> <span className="thread-avatar"><span className="avatar">GH</span></span> <div className="thread-body"> <p className="thread-header"> <span className="thread-author">Grace Hopper</span> <time className="thread-meta" dateTime="2026-11-12T10:31">35m</time> </p> <p className="thread-text">I will make the change this afternoon.</p> </div> </li> </ol></div><div class="card max-w(480) mx-auto"> <p class="m(0) text-sm"> Jump to <a class="link" href="#comment-ada">Ada's comment</a> or <a class="link" href="#comment-grace">Grace's reply</a>. </p> <ol class="thread"> <li class="thread-item flash" id="comment-ada" style="--flash-offset: 1rem"> <span class="thread-avatar"><span class="avatar">AL</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Ada Lovelace</span> <time class="thread-meta" datetime="2026-11-12T09:12">2h</time> </p> <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p> </div> </li> <li class="thread-item flash" id="comment-grace" style="--flash-offset: 1rem"> <span class="thread-avatar"><span class="avatar">GH</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Grace Hopper</span> <time class="thread-meta" datetime="2026-11-12T10:31">35m</time> </p> <p class="thread-text">I will make the change this afternoon.</p> </div> </li> </ol></div><template> <div class="card max-w(480) mx-auto"> <p class="m(0) text-sm"> Jump to <a class="link" href="#comment-ada">Ada's comment</a> or <a class="link" href="#comment-grace">Grace's reply</a>. </p> <ol class="thread"> <li class="thread-item flash" id="comment-ada" style="--flash-offset: 1rem"> <span class="thread-avatar"><span class="avatar">AL</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Ada Lovelace</span> <time class="thread-meta" datetime="2026-11-12T09:12">2h</time> </p> <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p> </div> </li> <li class="thread-item flash" id="comment-grace" style="--flash-offset: 1rem"> <span class="thread-avatar"><span class="avatar">GH</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Grace Hopper</span> <time class="thread-meta" datetime="2026-11-12T10:31">35m</time> </p> <p class="thread-text">I will make the change this afternoon.</p> </div> </li> </ol> </div></template>點選連結後,目標留言周圍會出現外框,接著淡出。
#運作方式
瀏覽器會將 ID 與網址片段相符的元素標記為頁面的 :target。flash 會在該元素周圍繪製外框,再讓它淡出。由於狀態取決於網址,因此會有以下兩種行為。
- 從其他頁面的連結進入、點選同頁連結或直接貼上網址,都會標示同一個元素。
- 點選指向不同片段的連結時,提示會移到新的目標。再次點選指向同一片段的連結時,效果不會重播。
提示使用外框,沿著元素原有的圓角繪製,無須配置額外空間或使用偽元素。元素的底面、陰影和懸停效果都會保留,因此同一個類別可用在卡片、表格列、標題與留言上。
#避開導覽列
片段連結會將目標捲動到檢視區頂端。如果頁面有黏附式導覽列,目標就可能被導覽列蓋住。flash 也會透過 --flash-offset 設定瀏覽器停止捲動時,目標距離檢視區頂端的偏移量,預設為 5rem。請將它設為頁面頂端固定內容的高度,再留一點空隙。
#減少動態效果
使用者啟用減少動態效果時,只要元素仍是目前的目標,周圍就會持續顯示一圈細線,以靜態方式標示連結位置。
#定位提示或文字標記
定位提示會短暫標出一個位置。若要持續強調內文中的字詞,請使用文字標記。若要告知使用者剛發生的事,請使用快顯通知。
#無障礙
- 定位提示是視覺效果。若目標元素並非連結或控制項,請加上
tabindex="-1",讓焦點在跳轉時移到目標,下一次按 Tab 時就會從該處繼續。 - 外框位於元素外側 4px 處,避開元素內容,讓文字維持原本的對比。
- 在強制色彩模式下,目標會以系統醒目提示色顯示外框,外框不會淡出。
#類別
| 類別 | 說明 |
|---|---|
flash | 用於帶有 id 的元素。當網址片段指向該元素時,會沿著元素本身的圓角顯示外框,然後逐漸淡出。 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--flash-offset | 5rem | 瀏覽器將元素捲動到定位時,元素與檢視區頂端的距離 |