Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an SVG Sprite Sheet #215

Closed
pierslawson opened this issue Apr 9, 2020 · 4 comments
Closed

Create an SVG Sprite Sheet #215

pierslawson opened this issue Apr 9, 2020 · 4 comments

Comments

@pierslawson
Copy link

Would it be possible to create a Sprite Sheet as part of your build process? Would allow people to quickly get working with your icons without resorting to img tags or using inline SVG.

@vanillajonathan
Copy link
Contributor

This could be interesting together with SVG fragment identifiers.
Example:

<img src="bootstrap-icons.svg#heart-fill" title="Filled heart" />

https://caniuse.com/#feat=svg-fragment
https://www.w3.org/TR/SVG/linking.html#SVGFragmentIdentifiers

@jake-low
Copy link

Just wanted to add that the sprite sheet approach is one of the suggested ways to use the Feather icon set. In particular, they suggest using <use xlink:href>, which for Bootstrap icons might look something like this:

<svg class="bi">
  <use xlink:href="path/to/bootstrap-icons.svg#heart-fill"/>
</svg>

The <use> creates a shadow DOM boundary, so this has some of the same limitations as using an <img> to embed an SVG (e.g. you won't be able to target elements within the SVG using CSS selectors in the parent document). More information on CSS-Tricks.

Despite these trade offs, I've personally found the combination of SVG spritesheets and <use> to be a useful technique. As I believe @pierslawson was alluding to, a sprite sheet has the advantage of not really needing any kind of build system or server-side templating (in contrast to inlining the actual individual SVG icons individually, which you'd probably want to do with a <?php include("path/to/icon.svg") ?> or similar). So I think it would be nice to have Bootstrap icons available as a sprite sheet, if possible.

@vanillajonathan
Copy link
Contributor

Feather Icons use a JavaScript to build a sprite sheet from the SVG icons.
https://github.com/feathericons/feather/blob/master/bin/build-sprite-string.js

@mdo mdo added this to To do in v1.0.0-alpha5 via automation May 30, 2020
@mdo
Copy link
Member

mdo commented May 30, 2020

Added in #274, coming in alpha 5.

@mdo mdo closed this as completed May 30, 2020
v1.0.0-alpha5 automation moved this from To do to Done May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v1.0.0-alpha5
  
Done
Development

No branches or pull requests

4 participants