javascript - Changing color of SVG which was embedded using <object> - Stack Overflow

I found only one solution on StackOverflow, but user said it didn't work for them. So, I embedded

I found only one solution on StackOverflow, but user said it didn't work for them.

So, I embedded SVG image to html:

<object id="help-center" type="image/svg+xml" data="assets/help_center.svg">
</object>

I don't understand how to change color on hover in this case.

In this snippet / SVG is right inside HTML and color changes on hover successfully. How to do same thing?

I found only one solution on StackOverflow, but user said it didn't work for them.

So, I embedded SVG image to html:

<object id="help-center" type="image/svg+xml" data="assets/help_center.svg">
</object>

I don't understand how to change color on hover in this case.

In this snippet https://jsfiddle/annaolsh/3j8dmnn2/ SVG is right inside HTML and color changes on hover successfully. How to do same thing?

Share Improve this question asked Oct 1, 2017 at 2:12 Present practicePresent practice 6012 gold badges16 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

css styles for a svg object can be applied for an inline svg only. If you embed it using an external url with the HTML <object> tag, you can not use the <style> tag within the document or you can not use an external css file to modify the svg content.

If you embed an external svg file, you have to add the <style> tag within the svg file itself as below.

<svg ...>
  <style>
    /* SVG specific fancy CSS styling here */
  </style>
  ...
</svg>

Otherwise get the source of svg file and inline it on the HTML file and then add your css styles directly. That's why your JSFiddle example worked and your provided code sample didn't work.

You can read more about how you can style svg objects here.
https://css-tricks./using-svg/#article-header-id-11

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744851370a4597147.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信