去掉超連結或按鈕點擊時出現的虛線邊框

來源:互聯網
上載者:User
  在前端製作的過程中會發現,一些文字/圖片連結,或者一些input控制項,在點擊時會在周圍出現虛線邊框,一般會在Firefox和IE瀏覽器下出現虛線框,Google下不會有。

  這些虛線邊框是作為對視覺設計的一種輔助,在不使用滑鼠,而用鍵盤Tab鍵進行頁面瀏覽時,會標示出當前所在的連結或控制項的位置,便於瀏覽。這對那些視覺有障礙的人士來說更是必不可少的。

  但是有些時候我們卻不想使用它們,因為瀏覽器對虛線框的解析有差異,並且不規則,所以在視覺設計上反而成為了某種缺陷。所以這種時候,我們想要禁用這些虛線邊框,使瀏覽者的視覺享受能夠完美無瑕。

  純CSS去掉超連結或按鈕點擊時出現的虛線邊框

<style type="text/css">a,input,button{ outline:none; }::-moz-focus-inner{border:0px;}</style></head><body> <a href="http://www.admin10000.com" target="_blank"><img src="http://www.admin10000.com/skin/logo.jpg" border="0"></a><a href="http://www.admin10000.com" target="_blank">admin10000.com</a><input type="button" value="admin10000.com"/><button>admin10000.com</button></body>

  從以上代碼可以看出,可以通過設定CSS屬性outline解決。

  FF存在bug,其中input,button標籤通過私人屬性::-moz-focus-inner特別處理

  以上方法在IE6、IE7下無效。可使用 onfocus 屬性解決,如下:

  <a href="http://www.admin10000.com" target="_blank" onfocus="this.blur()">admin10000.com</a>

  使用jquery方法只需一句,非常簡單,支援所有瀏覽器

  $("a,input,button").focus(function(){this.blur()});

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.