Given a transparent PNG displaying a simple shape in white, is it possible to somehow change the color of this through CSS? Some kind of overlay or what not?
相关问题
- Views base64 encoded blob in HTML with PHP
- How to get the background from multiple images by
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
I found this while googling, I found best working for me...
HTML
CSS
http://jsfiddle.net/a63b0exm/
You might want to take a look at Icon fonts. http://css-tricks.com/examples/IconFont/
EDIT: I'm using Font-Awesome on my latest project. You can even bootstrap it. Simply put this in your
<head>
:And then go ahead and add some icon-links like this:
Here's the full cheat sheet
--edit--
Font-Awesome uses different class names in the new version, probably because this makes the CSS files drastically smaller, and to avoid ambiguous css classes. So now you should use:
EDIT 2:
Just found out github also uses its own icon font: Octicons It's free to download. They also have some tips on how to create your very own icon fonts.
Think I have a solution for this that's a) exactly what you were looking for 5 years ago, and b) is a bit simpler than the other code options here.
With any white png (eg, white icon on transparent background), you can add an ::after selector to recolor.
See this codepen (applying the color swap on hover): http://codepen.io/chrscblls/pen/bwAXZO
I found this great codepen example that you insert your hex color value and it returns the needed filter to apply this color to png
CSS filter generator to convert from black to target hex color
for example i needed my png to have the following color #1a9790
then you have to apply the following filter to you png
You can use filters with
-webkit-filter
andfilter
: Filters are very new to browsers and are only supported in very modern browsers. You can change an image to grayscale, sepia and lot more (look at the example).So you can now change the color of a PNG file with filters.
Source
Yes :)