Can I add color to bootstrap icons only using CSS?

后端 未结 14 1389
说谎
说谎 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:55

    You can change color globally as well

    i.e.

     .glyphicon {
           color: #008cba; 
       }
    
    0 讨论(0)
  • 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

    // Sprite icons path
    // -------------------------
    @iconSpritePath:          "../img/glyphicons-halflings.png";
    @iconWhiteSpritePath:     "../img/glyphicons-halflings-white.png";
    

    and add this line

    @iconMagentaSpritePath:     "../img/glyphicons-halflings-magenta.png";
    

    In your sprites.less add

    /* Magenta icons with optional class, or on hover/active states of certain elements */
    .icon-magenta,
    .nav-pills > .active > a > [class^="icon-"],
    .nav-pills > .active > a > [class*=" icon-"],
    .nav-list > .active > a > [class^="icon-"],
    .nav-list > .active > a > [class*=" icon-"],
    .navbar-inverse .nav > .active > a > [class^="icon-"],
    .navbar-inverse .nav > .active > a > [class*=" icon-"],
    .dropdown-menu > li > a:hover > [class^="icon-"],
    .dropdown-menu > li > a:hover > [class*=" icon-"],
    .dropdown-menu > .active > a > [class^="icon-"],
    .dropdown-menu > .active > a > [class*=" icon-"],
    .dropdown-submenu:hover > a > [class^="icon-"],
    .dropdown-submenu:hover > a > [class*=" icon-"] {
      background-image: url("@{iconMagentaSpritePath}");
    }
    

    And use it like this:

    <i class='icon-chevron-down icon-magenta'></i>
    

    Hope it helps someone.

    0 讨论(0)
提交回复
热议问题