表單元素在 IE6/7 預設擁有立體邊框與焦點虛線框,嚴重影響視覺一致性。以下提供三種去除方案,涵蓋邊框與焦點線雙重需求。
<div class="wrap">
<input type="text" class="input_txt">
<input type="submit" value="submit" class="input_btn">
<input type="button" value="提交" class="input_btn">
</div>
input { margin: 0; padding: 0; }
.wrap { background-color: #0f0; }
.input_txt, .input_btn { border: 0 none; }
簡單、標準、相容性最好。搭配 background 自訂外觀。
<!--[if IE]>
<style>
input { margin: 0; padding: 0; filter: chroma(color=#000000); border: none; }
.wrap { background-color: #0f0; }
</style>
<![endif]-->
利用 chroma 濾鏡將特定顏色透明化,但實測在真實 IE7 環境常有副作用(如文字消失),不建議生產環境使用。
a:focus, *:focus { noFocusLine: expression(this.onFocus=this.blur()); }
IE 專有 expression 強制失焦,但會觸發無障礙問題(鍵盤使用者無法看到焦點)。現代做法改用:
:focus { outline: none; } /* 標準寫法 */
:focus-visible { outline: 2px solid #0066cc; } /* 僅鍵盤聚焦顯示,滑鼠點擊不顯示 */
border、background、border-radius。outline 或自訂 box-shadow,確保鍵盤可用性。<button> 替代 <input type="button">,樣式控制更靈活。