Home > Net >  set color code in data image svg is not working
set color code in data image svg is not working

Time:02-05

I want to change color in data image svg, right now current color is blue, i want to change its color to this color code #266C5E, can anyone please help me how to do that ?

data:image/svg xml;charset=utf8,<style type='text/css'>.squiggle{animation:shift 1s linear infinite;}@keyframes shift {from {transform:translateX(-10px);}to {transform:translateX(0);}}</style>

CodePudding user response:

You have to URL encode # in your svg code. So replace blue with #266C5E instead of #266C5E(which # is # URL encoded).

Here's the replaced version:

data:image/svg xml;charset=utf8,<style type='text/css'>.squiggle{animation:shift 1s linear infinite;}@keyframes shift {from {transform:translateX(-10px);}to {transform:translateX(0);}}</style>

div {
  width: 180px;
  height: 180px;
  
  background-image: url("data:image/svg xml;charset=utf8,<style type='text/css'>.squiggle{animation:shift 1s linear infinite;}@keyframes shift {from {transform:translateX(-10px);}to {transform:translateX(0);}}</style>");
}
<div></div>

  •  Tags:  
  • Related