如何删除 Firefox 中 SELECT/OPTION 下拉控件上的虚线?
在 Chrome 和其他浏览器中,我的下拉菜单看起来很好:
但是,在 Firefox 中,它有不需要的虚线:
我已经使用这些 CSS 语句成功删除了 buttons 和 input 元素中不需要的 Firefox 虚线:
button::-moz-focus-inner { border: 0; }
input::-moz-focus-inner { border: 0; }
所以我认为这些适用于 select/option 元素,但他们不:
select::-moz-focus-inner { border: 0; }
option::-moz-focus-inner { border: 0; }
如何删除此下拉列表中的虚线,以便它在 Chrome 和其他浏览器中显示?
附录
这些也不起作用:
select::-moz-focus-inner { border: 0; outline: 0 }
option::-moz-focus-inner { border: 0; outline: 0 }
也不起作用:
select { outline: 0; }
option { outline: 0; }
也不起作用:
select { outline: none; }
option { outline: none; }
In Chrome and other browsers my dropdown looks fine:
However, in Firefox it has unwanted dotted lines:
I have successfully removed the unwanted Firefox dotted lines for buttons and input elements with these CSS statements:
button::-moz-focus-inner { border: 0; }
input::-moz-focus-inner { border: 0; }
so I thought these would work for the select/option elements, but they don't:
select::-moz-focus-inner { border: 0; }
option::-moz-focus-inner { border: 0; }
How can I remove the dotted lines in this dropdown so that it appears as in Chrome and other browsers?
Addendum
These don't work either:
select::-moz-focus-inner { border: 0; outline: 0 }
option::-moz-focus-inner { border: 0; outline: 0 }
nor these:
select { outline: 0; }
option { outline: 0; }
nor these:
select { outline: none; }
option { outline: none; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
詹姆斯·布罗德(James Broad)的答案近乎完美,但选项项的“仅阴影”文本看起来很丑。这对我来说非常有效:
James Broad's answer is nearly perfect, but the "shadow-only" text for the option items looks ugly. This is what works perfectly for me:
这是组合黑客:
然后在每次选择后添加 tabindex=0 的输入
还有一些焦点“委托”的代码:
Here's combined hack for that:
Then add input with tabindex=0 after each select
And some code for focus "delegation":
https://stackoverflow.com/a/18853002/728855 上找到的解决方案似乎工作得很好。
简而言之:
其中 #000 是您的文本颜色。
the solution found on https://stackoverflow.com/a/18853002/728855 seems to work perfectly.
In short:
Where #000 is your text colour.
如果与
required
一起使用,如下面的代码:您需要为
select:required:invalid
设置相同的参数,如下所示:In case of using with
required
, like the code below:You will need set the same parameters for
select:required:invalid
like below:尝试使用
outline: 0,
适用于按钮try using
outline: 0,
works for buttons