javascript - Firefox 不会在点击时触发 css 焦点规则,而 Chrome 会。

标签 javascript css firefox

我正在尝试使用以下内容创建导航栏:

html:

<svg height="40" width="40">
  <a href="#">
    <circle cx="20" cy="20" r="20"></circle>
  </a>
</svg>
<svg height="40" width="40">
  <a href="#">
    <circle cx="20" cy="20" r="20"></circle>
  </a>
</svg>
<svg height="40" width="40">
  <a href="#">
    <circle cx="20" cy="20" r="20"></circle>
  </a>
</svg>

CSS:

a {
  color: #8899a6;
}

a:focus,
a:hover {
  color: #1da1f2;
}

circle {
  fill: currentcolor;
}

当您将鼠标悬停在链接上和单击它后,链接会变为蓝色。当我在 Chrome 中运行它时,它工作得很好。但是,它在 Firefox 中不起作用。有没有办法让这个在 Firefox 中工作?

最佳答案

当你把 a svg 中的元素, 它是使用 SVGAElement 创建的原型(prototype),而不是 HTMLAnchorElement .并且 Firefox 没有实现 focus SVGAElement 上的方法,而 Chrome 有。

如果可以,您可以简单地切换 a 的顺序和 svg元素,如果它是在 svg 之外创建的,然后是你的 a元素将是可聚焦的。

<a href="#" tabindex="1">
  <svg height="40" width="40">
    <circle cx="20" cy="20" r="20"></circle>
  </svg>
</a>
<svg height="40" width="40">
  <a href="#">
    <circle cx="20" cy="20" r="20"></circle>
  </a>
</svg>
<svg height="40" width="40">
  <a href="#">
    <circle cx="20" cy="20" r="20"></circle>
  </a>
</svg>

https://jsfiddle.net/2vhnqec0/

关于javascript - Firefox 不会在点击时触发 css 焦点规则,而 Chrome 会。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37377185/

相关文章:

selenium - Behat with Selenium Hub和Firefox错误:无法打开连接:从webdriver接收到的有效载荷有效,但意外出现json

javascript - 如何检查文档/文档快照中是否存在某个字段?

javascript - 返回语句中的 ES6 解构

javascript - 如何在 Meteor 中获取响应式(Reactive)数据源的旧值?

CSS:将 <divs> 放置在响应式调整大小的图像上

css - @keyframes 动画在 firefox 55.03 中不起作用

javascript - 按下删除键时 ASP.NET MVC 未知操作

html - 如何创建与父div 相同的子div 的边框高度?

html - 图像上的阴影

javascript - 使用 Greasemonkey 每 5 秒执行一次 Javascript?