html - SVG <a> 元素内的 <text> 元素在 IE 中没有下划线

标签 html css svg

请检查这个骗子:

https://plnkr.co/edit/jqPx9qpN3W1Jrix2axPw?p=preview

<div width="100px">
  <svg width="100px" viewBox="0 0 100 100">
      <a xlink:href="#" class="node">
          <text transform="translate(50 50)">hh2</text>
      </a>
  </svg>
</div>

a:hover {
    text-decoration: underline;
}

在 Chrome 上,悬停时您会看到一条下划线,但在 IE 上则没有下划线。我尝试用 css 解决但没有成功。

最佳答案

在 SVG 中,text-underline 的行为与 HTML 中略有不同。

在 SVG 中,the specification states that it shouldn't inherit.

Chrome 和 FF 似乎已经放宽了该限制。

要在 IE 中解决此问题,只需更改 CSS 规则以包含文本元素即可。

a:focus text, a:hover text {
    color: #23527c;
    text-decoration: underline;
}
    <h1>Hello Plunker!</h1>
    <div width="100px">
      <svg width="100px" viewBox="0 0 100 100">
          <a xlink:href="#" class="node">
              <text transform="translate(50 50)">hh2</text>
          </a>
      </svg>
    </div>

关于html - SVG <a> 元素内的 <text> 元素在 IE 中没有下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41415853/

相关文章:

javascript - 当在表格中输入了四个图像时,在 HTML 中删除一行

jquery - 将文本框拆分为 3 个区域

javascript - 第一次悬停后,悬停效果无法在每个元素上正常工作

c# - 使用 C# 将 SVG 转换为 PNG

html - 围绕其中心旋转 svg 元素

javascript - 在纯 JavaScript 中捕获 SVG onresize() ?

javascript - 使用工具提示拖放

html - 数据:image/png in the source of an image?是什么意思

html - jsfiddle layout broken : wrong input size. 大小存储在哪里?

javascript - 根据php数组值更改td的背景颜色