Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg-style

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-style

Change style attribute of SVG that are sourced from inside tags.

  • 0.1.0-d
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

svg-style

Description: Change the style attribute(e.g., fill:color) on SVG files that are sourced inside HTML 'img' tags.

Instructions:

  1. Add <script src="svg-style.js"></script>.

  2. Invoke svgStyle(imageClass,svgFile, style)

  • imageClass: The class you have put on the img tags.

  • svgFile: The svg file that src="" is loading on the img tag.

  • style: What you want the style="" to contain e.g. "fill:yellow; filter:invert(80%)"

Example:

Before: Screenshot

<style>
  .rainbow{
      display: flex;
      justify-content: space-around;
  }
</style>
<body>
    <div class="rainbow">
        <img class="red" src="macos.svg"><img>
        <img class="orange" src="macos.svg"><img>
        <img class="yellow" src="macos.svg"><img>
        <img class="green" src="macos.svg"><img>
        <img class="blue" src="macos.svg"><img>
        <img class="indigo" src="macos.svg"><img>
        <img class="violet" src="macos.svg"><img>

    </div>

// Loading svg-style.js
<script src="svg-style.js"></script>
// Call function svgStyle to change the style/fill attribute of an SVG file.
<script>
    svgStyle("red","macos.svg","fill:red;")
    svgStyle("orange","macos.svg","fill:#FF7F00;")
    svgStyle("yellow","macos.svg", "fill:yellow;")
    svgStyle("green","macos.svg","fill:rgb(0, 255, 0);")
    svgStyle("blue","macos.svg","fill:#FF7F00;")
    svgStyle("indigo","macos.svg","fill:indigo")
    svgStyle("violet","macos.svg", "fill:yellow; filter:invert(80%)")
</script>
</body>

After: Screenshot

Keywords

FAQs

Package last updated on 18 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc