Create a class called .branca
to use whenever you want the empty avatar. Use the properties of filter
of the CSS, brightness(100)
and ready, this will increase the brightness of the image and "pop" the white (as the photographers say), enough to make it white. If you want black, trade it for brightness(0)
and will totally take out the brightness of the image.
Here you can consult the support of browsers. Obviously it doesn’t work on IE.
body {
background-color: red;
}
.branca {
filter: brightness(100);
}
.preta {
filter: brightness(0);
}
<img class="" src="https://i.stack.imgur.com/uzMCi.png">
<img class="branca" src="https://i.stack.imgur.com/uzMCi.png">
<img class="preta" src="https://i.stack.imgur.com/uzMCi.png">
Here is a sandbox for you to test CSS filters.
OBS: It is interesting to test on deferent images to make sure that this technique will work in all cases, with small and large images. gif, . png, . bmp, . tif, . wmf or qq other format that has transparency and is interpreted by the browser...
I like SVG+xlink (tagged
<use>
), but the question is PNG :)– Guilherme Nascimento
So you prefer to always upload a larger file and modify with CSS (without great support, and in an unreliable way, as can be verified in the proposed solutions) than to use a more compact one in some situations?
– Bacco
It’s a good question of yours, but at least it’s worth learning about CSS. Maybe evaluating well makes sense to use one. Although anyway, the file is already loaded once on the page.
– Wallace Maxters