Twitter's bootstrap uses Icons by Glyphicons. They are "available in dark gray and white
" by default:
Is it possible to use some CSS trickery to change the colors of the icons? I was hoping for some other css3 brilliance that would prevent having to have an icon image set for each color.
I know you can change the background color of the enclosing (<i>
) element, but I'm talking about the icon foreground color. I guess it would be possible to inverse the transparency on the icon image and then set the background color.
So, can I add color to bootstrap icons only using CSS?
With the latest release of Bootstrap RC 3, changing the color of the icons is as simple as adding a class with the color you want and adding it to the span.
Default black color:
would become
CSS
Bootstrap 3 Glyphicons List
Another possible way to have bootstrap icons in a different color is to create a new .png in the desired color, (eg. magenta) and save it as /path-to-bootstrap-css/img/glyphicons-halflings-magenta.png
In your variables.less find
and add this line
In your sprites.less add
And use it like this:
Hope it helps someone.
Quick and dirty work around which did it for me, not actually coloring the icon, but surrounding it with a label or badge in the color you want;
It is actually very easy:
just use:
For example:
That's it.
You can change color globally as well
i.e.
The Bootstrap Glyphicons are fonts. This means it can be changed like any other text through CSS styling.
CSS:
HTML:
Example:
Watch the course Up and Running with Bootstrap 3 by Jen Kramer, or watch the individual lesson on Overriding core CSS with custom styles.