Change the color of glyphicons to blue in some- but not at all places using Bootstrap 2
Asked Answered
M

12

169

I am using the Bootstrap framework for my UI. I want to change the color of my glyphicons to blue, but not in all places. In some places it should use the default color.

I have referred to these two links, but I am not finding anything helpful.

Please note: I am using Bootstrap 2.3.2.

Maiga answered 20/8, 2013 at 12:18 Comment(1)
UPDATE: for BS4 just add 'text-primary' to the class of the icon.Garbe
M
24

Finally I found answer myself. To add new icons in 2.3.2 bootstrap we have to add Font Awsome css in you file. After doing this we can override the styles with css to change the color and size.

<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">

CSS

.brown{color:#9b846b}

If we want change the color of icon then just add brown class and icon will turn in brown color. It also provide icon of various size.

HTML

<p><i class="icon-camera-retro icon-large brown"></i> icon-camera-retro</p> <!--brown class added-->
<p><i class="icon-camera-retro icon-2x"></i> icon-camera-retro</p>
<p><i class="icon-camera-retro icon-3x"></i> icon-camera-retro</p>
<p><i class="icon-camera-retro icon-4x"></i> icon-camera-retro</p>
Maiga answered 22/8, 2013 at 15:20 Comment(1)
Newer versions (4.0.3 at the time of this comment) are available at bootstrapcdn.com/#fontawesome_tabFlummery
D
291

The icon will adopt the color from value of the color css property of it's parent.

You can either add this directly to the style:

<span class="glyphicon glyphicon-user" style="color:blue"></span>

Or you can add it as a class to your icon and then set the font color to it in CSS

HTML

<span class="glyphicon glyphicon-search"></span>
<span class="glyphicon glyphicon-user blue"></span>
<span class="glyphicon glyphicon-trash"></span>

CSS

.blue {
    color: blue;
}

This fiddle has an example.

Devonian answered 20/8, 2013 at 12:32 Comment(3)
Thanks. I am using Bootstrap /2.3.2/.It is not working for me.Maiga
Still you can use it, delete all the css rules for glyphicon and add this css file netdna.bootstrapcdn.com/bootstrap/3.0.0-rc2/css/… and download the glyphicon fonts from bootstrap 3, this will workout.Devonian
@VikasGhodke, that would still require migration of the whole project to version 3.Solana
I
203

Simply apply Twitter Bootstrap text-success class on Glyphicon:

<span class="glyphicon glyphicon-play text-success">начал работу</span>

enter image description here

Full list of available colors: Bootstrap Documentation: Helper classes
(Blue is present also)

Iconoclasm answered 1/9, 2014 at 21:38 Comment(6)
why to mix oranges with apples? :\Wilsey
* начал работу is started a work. I'd writen the answer on fly and I did not thought that it would be voted high. Thus the screenshot was made in russian from my previous app to show how the markup looked.Iconoclasm
I find it very appropriate if the icon must be shown exacly because there have been a success in the operation.Pyxis
This is better because the color applied will conform to the current Bootstrap theme color schemeSusurrant
@naXa try text-danger. Here's a full list of colours.Sidelight
@naXa ty! I fixed the link!Iconoclasm
M
24

Finally I found answer myself. To add new icons in 2.3.2 bootstrap we have to add Font Awsome css in you file. After doing this we can override the styles with css to change the color and size.

<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">

CSS

.brown{color:#9b846b}

If we want change the color of icon then just add brown class and icon will turn in brown color. It also provide icon of various size.

HTML

<p><i class="icon-camera-retro icon-large brown"></i> icon-camera-retro</p> <!--brown class added-->
<p><i class="icon-camera-retro icon-2x"></i> icon-camera-retro</p>
<p><i class="icon-camera-retro icon-3x"></i> icon-camera-retro</p>
<p><i class="icon-camera-retro icon-4x"></i> icon-camera-retro</p>
Maiga answered 22/8, 2013 at 15:20 Comment(1)
Newer versions (4.0.3 at the time of this comment) are available at bootstrapcdn.com/#fontawesome_tabFlummery
S
7

You can do this as well, hopeit helps

<span style="color:black"><i class="glyphicon glyphicon-music"></i></span>
Salchunas answered 19/8, 2014 at 20:55 Comment(0)
S
7

For bootstrap 3.0, this worked for me:

.myclass .glyphicon {color:blue !important;}
Slangy answered 19/5, 2015 at 15:25 Comment(0)
B
3

I created an alternate colors library for bootstrap 2.3.2 it's available and simple to use for anyone interested in more colors for the old glyphicons library.

Battleax answered 5/9, 2013 at 7:4 Comment(0)
R
3

Yes, you can set the icons to the white color. here is how it worked for me.

Bootstrap <3

HTML

<i class="icon-ok icon-white"></i>

This would make your icon appear white.

Repeal answered 15/11, 2013 at 7:0 Comment(1)
The icon-white worked for me with Bootstrap 2. The question asked for blue, but knowing there's a single class for white seems handy.Cyrilcyrill
C
3

If it is only a bootstrap icon. Note that icons are under text or rather typography. Just add the text color class like this. E.g text-primary, text-info and so on and so forth to the icon class:

<i class="icon features-icon icons8-collaboration-2 text-primary"></i>
<i class="icon features-icon icons8-collaboration-2 text-secondary"></i>
Caralie answered 22/10, 2017 at 15:9 Comment(0)
G
2

Bootstrap >= v4.0 dropped glyphicon support

Dropped the Glyphicons icon font. If you need icons, some options are:

the upstream version of Glyphicons

Octicons

Font Awesome

Source: https://v4-alpha.getbootstrap.com/migration/#components

If you are using Bootstrap >= v4.0 or newer, you can use existing style classes of bootstrap such as text-success,text-warning etc.

For example, if you are using fontawesome:

<i class="fa fa-tag text-danger" aria-hidden="true"></i>
Gymnast answered 3/1, 2018 at 4:17 Comment(0)
W
2

CSS:

.blue-icon{
color:blue !important;
}

HTML

<i class="fa fa-wrench blue-icon"></i>

Glyphicons are removed in 4.0, i recommend Font-awesome 4 or newer :)

Wellknit answered 12/1, 2018 at 13:10 Comment(0)
D
1

All previous answers are correct but here is a simple and quick way if you only need one icon in one place to change it's color:

   <p style="color:green">Time icon: <span class="glyphicon glyphicon-time" ></span></p>  

enter image description here

Darrickdarrill answered 29/7, 2018 at 17:38 Comment(0)
S
0

Color not work, if you use for bootstrap font png image, as i.

[class^="icon-"],
[class*=" icon-"] {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-top: 1px;
  *margin-right: .3em;
  line-height: 14px;
  vertical-align: text-top;
  background-image: url("../img/glyphicons-halflings.png");
  background-position: 14px 14px;
  background-repeat: no-repeat;
}

HTML5 use css filter to colorize image, example

filter: invert(100%)  contrast(2) brightness(50%) sepia(40%) saturate(450%) hue-rotate(-50deg);
Scrutineer answered 26/6, 2019 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.