如何删除 Firefox 中 SELECT/OPTION 下拉控件上的虚线?

发布于 2024-10-15 20:51:43 字数 1034 浏览 2 评论 0原文

Chrome 和其他浏览器中,我的下拉菜单看起来很好

在此处输入图像描述

但是,在 Firefox 中,它有不需要的虚线

enter image这里的描述

我已经使用这些 CSS 语句成功删除了 buttonsinput 元素中不需要的 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:

enter image description here

However, in Firefox it has unwanted dotted lines:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

似狗非友 2024-10-22 20:51:43

詹姆斯·布罗德(James Broad)的答案近乎完美,但选项项的“仅阴影”文本看起来很丑。这对我来说非常有效:

select:-moz-focusring {
  color:transparent;
  text-shadow:0 0 0 #000; /* your normal text color here */
}
select:-moz-focusring * {
  color:#000; /* your normal text color here */
  text-shadow:none;
}

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:

select:-moz-focusring {
  color:transparent;
  text-shadow:0 0 0 #000; /* your normal text color here */
}
select:-moz-focusring * {
  color:#000; /* your normal text color here */
  text-shadow:none;
}
静赏你的温柔 2024-10-22 20:51:43

这是组合黑客:

select:focus {
    outline: 1px solid white;
    outline-offset: -2px;
}
select ~ input[type=button] {
    -moz-appearance: menulist-button;
    margin-left: -19px;
    width: 18px;
    height: 18px;
    z-index: 10;
}

然后在每次选择后添加 tabindex=0 的输入
还有一些焦点“委托”的代码:

$("select ~ input[type=button]").addEvent('focus', function(){
  this.getPrevious().focus();
});

Here's combined hack for that:

select:focus {
    outline: 1px solid white;
    outline-offset: -2px;
}
select ~ input[type=button] {
    -moz-appearance: menulist-button;
    margin-left: -19px;
    width: 18px;
    height: 18px;
    z-index: 10;
}

Then add input with tabindex=0 after each select
And some code for focus "delegation":

$("select ~ input[type=button]").addEvent('focus', function(){
  this.getPrevious().focus();
});
生生漫 2024-10-22 20:51:43

https://stackoverflow.com/a/18853002/728855 上找到的解决方案似乎工作得很好。

简而言之:

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

其中 #000 是您的文本颜色。

the solution found on https://stackoverflow.com/a/18853002/728855 seems to work perfectly.

In short:

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

Where #000 is your text colour.

猫七 2024-10-22 20:51:43

如果与 required 一起使用,如下面的代码:

<select required="true">
    <option value="" selected="true" disabled="true" hidden="true">Select a Option</option>
    <option value="">Option</option>
</select>

您需要为 select:required:invalid 设置相同的参数,如下所示:

select {
  &:required {
    &:invalid {
      color: transparent;
      text-shadow: 0 0 0 rgba(0, 0, 0, .4);
    }
  }

  &:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 rgba(0, 0, 0, .4);
  }
}

In case of using with required, like the code below:

<select required="true">
    <option value="" selected="true" disabled="true" hidden="true">Select a Option</option>
    <option value="">Option</option>
</select>

You will need set the same parameters for select:required:invalid like below:

select {
  &:required {
    &:invalid {
      color: transparent;
      text-shadow: 0 0 0 rgba(0, 0, 0, .4);
    }
  }

  &:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 rgba(0, 0, 0, .4);
  }
}
鹤仙姿 2024-10-22 20:51:43

尝试使用 outline: 0, 适用于按钮

try using outline: 0, works for buttons

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文