twbs/icons

Add DATA URI choice to the individual icon pages

Open

#903 opened on May 29, 2021

View on GitHub
 (2 comments) (2 reactions) (0 assignees)JavaScript (6,955 stars) (1,049 forks)batch import
docsenhancementhelp wanted

Description

Not a bug, rather a feature request.

Using SVG as a data URI for background image has wide support (https://caniuse.com/svg-css) and it would be so handy if an ICON's page showed the right data uri format.

Roughly speaking the format needs to remove the width and height settings and then be encodeURIComponent() encoded (I think.. I'm not 100% confident of the encoding rules for data uri's).

By removing the width/height setting of the SVG element then the SVG's size will be set based on the element it is being applied to.

The data uri format looks like:

background-image: url(data:image/svg+xml;utf8,[...encodeURIComponent() of the SVG element...]); 

This could be displayed below the "Copy HTML" section as:

Copy CSS background-image
Paste the CSS right into your project's code.
[background-images... and the copy function]

I put together a mock up at https://imgur.com/a/KvbOpCf (look to the bottom right to see the new Copy CSS block).

I have also put together an example of using an icon via CSS background-image at https://jsfiddle.net/7201rjtz/

Thanks!

EDIT: Instead of a utf8 data uri it could just as well be base64 (slightly smaller too): https://jsfiddle.net/7201rjtz/1/ (added Example2 css class with data uri using base64).

Contributor guide