css - 如何在不删除 Firefox/IE 轮廓焦点的情况下自定义输入边框

标签 css firefox focus accessibility outline

重要:我不想为可访问性 (a11y) 目的自定义/删除焦点样式。它基本上是 impossible to mimic all the different focus styles of browsers/operating systems

自定义输入/文本区域的外观会在元素获得焦点时移除轮廓样式。它还添加了奇怪的边框等。

这种行为背后的原因是什么,在我看来它破坏了可访问性?如何在修改背景、边框颜色等简单 CSS 属性时不覆盖焦点样式?

我在 Firefox Mac 和 IE 11(Chrome 运行良好)上进行了测试,也许其他浏览器的行为相同。 这是一个在浏览器中尝试的 Codepen:https://codepen.io/lbineau/pen/dLgwoo

<label for="customized-input">Customized input</label>
<input id="customized-input" type="text" />

<label for="native-input">Native input</label>
<input id="native-input" type="text" />

预期结果:即使自定义输入边框,也应显示默认轮廓。

实际结果:输入框聚焦时不显示轮廓。

最佳答案

我不知道这背后的原因。

但是你可以用下面的代码覆盖它:

#customized-input:-moz-focusring {
  outline: Highlight solid 1px; 
}

关于css - 如何在不删除 Firefox/IE 轮廓焦点的情况下自定义输入边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55831265/

相关文章:

javascript - 如何在 Bootstrap 下拉菜单上编辑 CSS?

css - 中心 ul Sprite 导航

html - div 碰撞 css

html - Firefox 对某些图像说 "Could Not Load Image",自动添加奇怪的类

android - 在 ListView 中禁用项目焦点

c# - 识别 Windows 8 风格 (Metro) 应用程序何时处于后台或失去焦点

javascript - 使用 javascript 调整 Cycle2 的大小让事情变得紧张

javascript - 为什么 Firefox + 我的代码会破坏 FireFox 刷新

jQuery 调用查找函数在 Firefox 中给出 “not well-formed” 错误

Angular4向导第一个文本字段专注于下一步