如何删除按钮和链接上Firefox的虚线轮廓?

CSS

梅Tom猿

2020-03-18

我可以使Firefox在链接上不显示点状的难看的焦点轮廓

a:focus { 
    outline: none; 
}

但是我也该如何对<button>标签执行此操作当我这样做时:

button:focus { 
    outline: none; 
}

单击这些按钮时,它们的焦点轮廓仍为虚线。

(是的,我知道这是一个可用性问题,但是我想提供适合于设计的我自己的焦点提示,而不是难看的灰色点)

第2046篇《如何删除按钮和链接上Firefox的虚线轮廓?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

19个回答
Mandy梅 2020.03.18

After trying many options from the above only the following worked for me.

*:focus, *:visited, *:active, *:hover  { outline:0 !important;}
*::-moz-focus-inner {border:0;}
斯丁Tony泡芙 2020.03.18

You can try button::-moz-focus-inner {border: 0px solid transparent;} in your CSS.

EvaAPro 2020.03.18

Along with Bootstrap 3 I used this code. The second set of rules just undo what bootstrap does for focus/active buttons:

button::-moz-focus-inner {
  border: 0;    /*removes dotted lines around buttons*/
}

.btn.active.focus, .btn.active:focus, .btn.focus, .btn.focus:active, .btn:active:focus, .btn:focus{
  outline:0;
}

NOTE that your custom css file should come after Bootstrap css file in your html code to override it.

前端Stafan 2020.03.18

This works on firefox v-27.0

 .buttonClassName:focus {
  outline:none;
}
凯泡芙Davaid 2020.03.18

The CSS code below works to remove this:

a:focus, a:active, 
button::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner,
select::-moz-focus-inner,
input[type="file"] > input[type="button"]::-moz-focus-inner {
    border: 0;
    outline : 0;
}
路易Harry 2020.03.18

Remove dotted outline from links, button and input element.

a:focus, a:active,
button::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner {
    border: 0;
    outline : 0;
}
理查德十三Davaid 2020.03.18

You might want to intensify the focus rather than get rid of it.

button::-moz-focus-inner {border: 2px solid transparent;}

button:focus::-moz-focus-inner {border-color: blue} 
卡卡西凯 2020.03.18
button::-moz-focus-inner { border: 0; }

Where button can be whatever CSS selector for which you want to disable the behavior.

SamGil 2020.03.18

It looks like the only way to achieve this is by setting

browser.display.focus_ring_width = 0

in about:config on a per browser basis.

达蒙GO 2020.03.18

Simply add this css for select box

select:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 #000;
}

This is working fine for me.

Pro斯丁 2020.03.18

Tested on Firefox 46 and Chrome 49 using this code.

input:focus, textarea:focus, button:focus {
    outline: none !important;
}

Before (white dots are visible )

input with white dots

After ( White dots are invisible ) enter image description here

If you want to apply only on few input fields, buttons etc. Use the more specific code.

input[type=text] {
  outline: none !important;
}

Happy Coding!!

小小MandyGil 2020.03.18

This will get the range control:

:focus {
    outline:none;
}
::-moz-focus-inner {
    border:0;
}
input[type=range]::-moz-focus-outer {
    border: 0;
}

From: Remove dotted outline from range input element in Firefox

番长Itachi 2020.03.18

There is many solutions found on the web for this, many of which work, but to force this, so that absolutely nothing can highlight/focus once a use the following:

::-moz-focus-inner, :active, :focus {
    outline:none;
    border:0;
    -moz-outline-style: none;
}

This just adds that little bit extra security & seals the deal!

神无逆天GO 2020.03.18

Tried most of the answers here, but none of them worked for me. When I realized that I have to get rid of the blue outline on buttons on Chrome too, I found another solution. Remove blue border from css custom-styled button in Chrome

This code worked for me on Firefox version 30 on Windows 7. Perhaps it might help somebody else out there :)

button:focus {outline:0 !important;}
古一NearEva 2020.03.18
:focus, :active {
    outline: 0;
    border: 0;
}
小胖十三 2020.03.18

The below worked for me in case of LINKS, thought of sharing - in case someone is interested.

a, a:visited, a:focus, a:active, a:hover{
    outline:0 none !important;
}

Cheers!

Stafan樱 2020.03.18

If you prefer to use CSS to get rid of the dotted outline:

/*for FireFox*/
    input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner
    {   
        border : 0;
    } 
/*for IE8 and below */
    input[type="submit"]:focus, input[type="button"]:focus
    {     
        outline : none; 
    }
路易LEY 2020.03.18

无需定义选择器。

:focus {outline:none;}
::-moz-focus-inner {border:0;}

但是,这违反了W3C的可访问性最佳做法。该大纲可帮助那些使用键盘导航的人。

https://www.w3.org/TR/WCAG20-TECHS/F78.html#F78-examples

樱Davaid 2020.03.18
button::-moz-focus-inner {
  border: 0;
}

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android