svg element inside element gets underli

2019-06-25 11:34发布

The title pretty much says it all. My SVG <text> element nested within an <a> element gets an underline on mouse hover, but only in Chrome. There is no underline in Firefox or IE.

Is there some attribute I should set to remove the underline in Chrome as well?

Here is my code

<a xlink:href="#" class="node">
    <title>Some title</title>
    <circle class="little" r="50" cx="60" cy="360" fill="#0088cc"></circle>
    <text font-size="20px" font-weight="bold" fill="white" text-decoration="none" text-anchor="middle" dominant-baseline="central" x="60" y="360">Some text</text>
</a>

2条回答
三岁会撩人
2楼-- · 2019-06-25 12:13

For safari I had to wrap the svg element in a div and apply the style

text-decoration: none !important;

to that div (I am using sass):

.header__logo {
    text-decoration: none !important;  // Safari adds text decoration to    text element inside svg
    a:-webkit-any-link,
    a:hover {
        text-decoration: none;
    }
}
查看更多
对你真心纯属浪费
3楼-- · 2019-06-25 12:14

This doesn't happen when you reproduce your code in a jsfiddle, so I'm guessing your stylesheet has something like this:

a:hover {
   text-decoration: underline;
}

Try overriding this behavior by writing:

svg a:hover {
   text-decoration: none;
}
查看更多
登录 后发表回答