Can I add color to bootstrap icons only using CSS?

后端 未结 14 1388
说谎
说谎 2020-11-28 02:58

Twitter\'s bootstrap uses Icons by Glyphicons. They are \"available in dark gray and white\" by default:

相关标签:
14条回答
  • 2020-11-28 03:42

    It is actually very easy:

    just use:

    .icon-name{
    color: #0C0;}
    

    For example:

    .icon-compass{
    color: #C30;}
    

    That's it.

    0 讨论(0)
  • 2020-11-28 03:43

    Because the glyphicons are now fonts, one can use the contextual classes to apply the appropriate color to the icons.

    For example: <span class="glyphicon glyphicon-info-sign text-info"></span> adding text-info to the css will make the icon the info blue color.

    0 讨论(0)
  • 2020-11-28 03:46

    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;

    <span class="label-important label"><i class="icon-remove icon-white"></i></span>
    <span class="label-success label"><i class="icon-ok icon-white"></i></span>
    
    0 讨论(0)
  • 2020-11-28 03:46

    I thought that I might add this snippet to this old post. This is what I had done in the past, before the icons were fonts:

    <i class="social-icon linkedin small" style="border-radius:7.5px;height:15px;width:15px;background-color:white;></i>
    <i class="social-icon facebook small" style="border-radius:7.5px;height:15px;width:15px;background-color:white;></i>
    

    This is very similar to @frbl 's sneaky answer, yet it does not use another image. Instead, this sets the background-color of the <i> element to white and uses the CSS property border-radius to make the entire <i> element "rounded." If you noticed, the value of the border-radius (7.5px) is exactly half that of the width and height property (both 15px, making the icon square), making the <i> element circular.

    0 讨论(0)
  • 2020-11-28 03:50

    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:

    <h1>Password Changed <span class="glyphicon glyphicon-ok"></span></h1>
    

    would become

    <h1>Password Changed <span class="glyphicon glyphicon-ok icon-success"></span></h1>
    

    CSS

    .icon-success {
        color: #5CB85C;
    }
    

    Bootstrap 3 Glyphicons List

    0 讨论(0)
  • 2020-11-28 03:50

    Just use the GLYPHICONS and you will be able to change color just setting the CSS:

    #myglyphcustom {
        color:#F00;
    }
    
    0 讨论(0)
提交回复
热议问题