【问题标题】:Remove double outline on button and it's text inside删除按钮上的双轮廓和里面的文本
【发布时间】:2018-11-26 12:59:10
【问题描述】:

我有一个button,里面有一段文字。我在:active 和focus 状态上设置了outline 的样式,就像下面的sn-p 一样。我在firefox 上有一个奇怪的行为:当我进入button 时,在button 周围有一个outline,在按钮内的文本周围有一个outline(见下面的截图)。我刚刚在firefox 上遇到了这个奇怪的问题。我怎样才能解决这个问题。我发现的问题的唯一答案是使用outline: none;,但这不是我想要的。我想要button 周围的轮廓。

outline chrome Windows 10:

firefox 上的outline(问题)Windows 10:

.button__btn {
  background-color: transparent;
  border: 2px solid blue;
  font-size: 20px;
  padding: 8px 24px;
  text-align: center;
}

.button__btn:active,
.button__btn:focus {
  outline: 1px dotted black;
  outline-offset: 5px;
}
<div class="button">
  <button class="button__btn">I'm a default button</button>
</div>

这里还有一个 codepen:https://codepen.io/STWebtastic/pen/EORBpE

【问题讨论】:

    标签: html css windows firefox outline


    【解决方案1】:

    请使用以下代码:

    button::-moz-focus-inner {
       border: 0;
    }
    

    它将删除所有按钮的Firefox内部轮廓。

    这里也提到了这个建议:How to remove Firefox's dotted outline on BUTTONS as well as links?

    【讨论】:

    • 是的,几个小时前我在互联网上找到了相同的链接。谢谢!
    • 这似乎也是特定Firefox版本的错误:我在Windows 10上,我的Firefox是63.0.3(64位)。我的同事在具有相同 firefox 版本的 Macbook 上遇到了同样的问题,而另一位同事在不同版本上没有此错误。
    【解决方案2】:

    试试这个:

    CSS

    .button{
         -moz-user-select: none; /* Firefox */
          -ms-user-select: none; /* Internet Explorer - Edge */
              user-select: none; /* Chrome and Opera */
    }
    

    user-select 属性指定元素的文本是否可以 被选中。

    【讨论】:

    • 我试过了,但问题仍然存在...我使用的是 Windows 10...我的一个朋友在 Firefox Mac 上尝试过,但他无法重现该问题,看起来和 chrome 一样...
    猜你喜欢
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2016-03-07
    • 1970-01-01
    • 2014-01-02
    相关资源
    最近更新 更多