Encoding '#' in SVG in data URL in CSS
I had to change a '#' to '%23' in an SVG in a 'data' URL of a 'background-image' property in CSS.
I had to do this when changing RGB colors to hexadecimal when 'minimising' my page using a bit of Perl:
s/rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\)/sprintf("%s23%02x%02x%02x","%",$1,$2,$3)/eg;
(My old version of Perl does not allow '%%' in the 'sprintf' in the substitution)
All the other 'special' characters are encoded in the SVG in the 'data' URL.
The 'background-image' property looks like:
url("data:image/svg+xml;charset=utf8,%3Csvg%20viewBox%3D%220%200%20168%...
There are online tools to do the encoding.
A PNG image would need full 'base64' encoding to go in a 'url' but an SVG does not.
There are more tips at: bbingo.xyz/techtips/
Comments
Post a Comment