Change SVG Fill when SVG is embedded in the CSS [duplicate] - css

I have an SVG background image embedded in a CSS file as a data url:
.what { background: url('data: image/svg+xml; utf8, <svg> ... </svg') }
I want another element to have the same background image, only in a different color, but I don't want to repeat the whole SVG code.
<div class="what one">...</div>
<div class="what two">...</div>
So how do I change the color of a background SVG image?
No Javascript, please.
None of the other related questions answered this, because the solutions given there rely on serving two different files, which I want to avoid because I want to minimize file size for mobile users.

Apparently, as Noah Blon explains, it is possible to style the color of an SVG background image using CSS filters.
An example he gives on his site is:
.icon-blue {
-webkit-filter: hue-rotate(220deg) saturate(5);
filter: hue-rotate(220deg) saturate(5);
}
Please visit his site for more information and two other solutions that do not involve changing the color but SVG background sprites and creating an "inverted" SVG that covers the background and is transparent where the background color shines through to create a colored form.
Unfortunately, IE does not support filters.

You can't restyle the contents of a background image with CSS. It doesn't matter if it's an external SVG, or one applied as a Data URI.

Check out this webpage: https://css-tricks.com/using-svg/
Part way down the page is a header called "Now you can control with CSS!"
They appear to be changing the color of the image inline with statements such as
.kiwi {
fill: #94d31b;
}

Related

change image existing color from one to another one

I have calendar image with I want to change to another color. I dont have photoshop to edit the color. Is it possible to change color with css?
I want to apply color to this color: #26416c;
If it's an image, you're limited to editing it with an image editor, or using what is currently experimental CSS technology by using the filter property:
img {
-webkit-filter: hue-rotate(90deg);
filter: hue-rotate(90deg);
}
<img src="http://i.stack.imgur.com/v96I5.png" />

Change color of data url embedded SVG image

I have an SVG background image embedded in a CSS file as a data url:
.what { background: url('data: image/svg+xml; utf8, <svg> ... </svg') }
I want another element to have the same background image, only in a different color, but I don't want to repeat the whole SVG code.
<div class="what one">...</div>
<div class="what two">...</div>
So how do I change the color of a background SVG image?
No Javascript, please.
None of the other related questions answered this, because the solutions given there rely on serving two different files, which I want to avoid because I want to minimize file size for mobile users.
Apparently, as Noah Blon explains, it is possible to style the color of an SVG background image using CSS filters.
An example he gives on his site is:
.icon-blue {
-webkit-filter: hue-rotate(220deg) saturate(5);
filter: hue-rotate(220deg) saturate(5);
}
Please visit his site for more information and two other solutions that do not involve changing the color but SVG background sprites and creating an "inverted" SVG that covers the background and is transparent where the background color shines through to create a colored form.
Unfortunately, IE does not support filters.
You can't restyle the contents of a background image with CSS. It doesn't matter if it's an external SVG, or one applied as a Data URI.
Check out this webpage: https://css-tricks.com/using-svg/
Part way down the page is a header called "Now you can control with CSS!"
They appear to be changing the color of the image inline with statements such as
.kiwi {
fill: #94d31b;
}

Change css background image depending on site

Is it possible for css to change background image depending on which site we are?
For example, when I am on a index.php, I want to see images/index.png, and when I am on first.php I want to have /images/image.png.
You can change the background by leaving it blank on css.
<style>
body
{
background-image: url(/images/index.png);
}
</style>
And use that on every webpage.

Change fill color of data-URI SVG path in pseudo element

Is it possible to use CSS to change the color of a SVG path which is within a pseudo element data-URI?
External Site
CSS:
a[href^="http://"]:after { content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMTVweCIgaGVpZ2h0PSIxM3B4IiB2aWV3Qm94PSItMyAyMSAxNSAxMyIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAtMyAyMSAxNSAxMyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZmlsbD0iIzk5OTk5QSIgZD0iTTEyIDIxSDB2M2gtM3YxMEg5di0zaDNWMjF6IE04IDMzSC0ydi04aDJ2Nmg4VjMzeiBNOSAyN0g3djJINXYtMkgzdi0yaDJ2LTJoMnYyaDJWMjd6Ii8+PC9zdmc+); }
a[href^="http://"]:hover:after path { fill: #000; }
Not like that, since the svg contents is in another document. Styles don't apply across documents.
And since the svg will be treated as a dumb image when referenced like this via CSS, putting the path hover style inside the svg won't help either.
I'd recommend putting the svg inline in the document if you want to style some shapes inside of it.
That said, another possibility for changing the color of an image is using filters, since they can be applied from outside. If your image is simple that might work.

Changing background of wordpress theme

I have been trying to change the background image of the wordpress theme but i am unable to change it.
I tried:
body {
background : url('images/squad.jpg');
}
I placed this code under design-settings in custom css styles. But i do not see any changes
in wordperss stylesheet file, search for body and html selectors and check if any background applied to them.
in html selector add this property:
backbround: #fff url(imagePath) no-repaet top left;
you can change #fff to the color that is more related to your background image. it's not necessary, but it's best practice.
if your background image is a pattern and you want it to be repeated, change no-repeat to repeat this should work.
Is your css file is in separate folder?
try this
body {background : url('../images/squad.jpg');}

Resources