Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Managing SVG images

Managing SVG images

Process improvements on how to manage and use SVG images in web applications. Also shows setup details and gotchas.

Olivier Robert

September 08, 2017
Tweet

More Decks by Olivier Robert

Other Decks in Programming

Transcript

  1. Intro • Improve our process to manage and use SVG

    images in web projects • Show setup details and gotchas
  2. Now • Shell script ◦ Rely on NPM package “svg-sprite”

    ◦ 1 script per sprite image • Outputs ◦ 1 stylesheet ◦ 1 SVG sprite • Use with a Rake task (optional, Rails project only)
  3. Issues • Sizing in “rem“ does not work sometimes, have

    to fallback to “pixel” ⇒ Issue in the generated stylesheet due to % sizing • Duplication of icons for each color
  4. New Process • Use SVG tag • Use xlink:href with

    an ID ⇒ No SVG code • Need to define the viewbox to match the icon size
  5. New Process • Insert the sprite image a the stop

    of the body ⇒ Needs to be defined first • Use HTML attribute “hidden” to hide it
  6. Things to know • Can access any part of the

    SVG as CSS selectors: ◦ “<path/>” ◦ “<g/>” ⇒ Great for animation • Old version of IE still requires a polyfill: SVG4everybody ⇒ There is a webpack plugin
  7. Thanks! Contact Nimbl3 [email protected] 399 Sukhumvit Road, Interchange 21 Klongtoey

    nua, Wattana Bangkok 10110 20th Floor, Central Tower 28 Queen's Road Central, Hong Kong nimbl3.com