連結被點擊時出現虛線框(焦點輪廓),松開滑鼠後仍殘留,影響視覺美觀。
<a href="..." hidefocus="true">連結</a>
outline: none(Firefox 1.5+、Chrome、Safari、Edge、Opera).HideFocus { outline: none; }
套用:<a class="HideFocus">... 或全域 a { outline:none; }。
.HideFocus {
hide-focus: expression(this.hideFocus=true); /* IE */
outline: none; /* Firefox+ */
}
link.htc:
<public:attach event="onfocus" onevent="this.hideFocus=true" />
CSS:
a { behavior: url(link.htc); }
a:focus { outline: 0; } /* Firefox 補強 */
同樣適用於 <input>、<button> 等可聚焦元素。
移除焦點輪廓會嚴重損害鍵盤導航使用者體驗。建議保留焦點樣式,改為自訂明顯風格:
a:focus {
outline: 2px solid #007bff;
outline-offset: 2px;
/* 或 */
box-shadow: 0 0 0 3px rgba(0,123,255,.4);
}
既美觀又無障礙,符合 WCAG 2.1 SC 2.4.7 Focus Visible。