Bootstrap font icon
This chapter will explain font icons (Glyphicons) and understand its use through some examples. Bootstrap comes bundled with glyphs in over 200 font formats. First, let us first understand what a font icon is.
What is a font icon?
Font Icon is an icon font used in web projects. Although, Glyphicons Halflings requires a commercial license, you can use these icons for free through project-based Bootstrap.
In order to express our gratitude to the icon author, we hope that you will include a link to the GLYPHICONS website when using it.
Get the font icon
We have downloaded the Bootstrap 3.x version in the Environment Installation chapter and understood its directory structure. Font icons can be found in the fonts folder, which contains the following files:
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
The relevant CSS rules are written in bootstrap.css and bootstrap-min in the css folder in the dist folder. css file.
Font icon list
Click here to view the list of available font icons.
CSS Rule Explanation
The following CSS rules constitute the glyphicon class.
font-family: 'Glyphicons Halflings';
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
.glyphicon {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
-webkit-font-smoothing: antialiased;
font-style: normal;
font-weight: normal;
line-height: 1;
-moz- osx-font-smoothing: grayscale;
}
So the font-face rule actually declares the font-family and position where the glyphicons are found.
.glyphicon class declares a relative position offset 1px from the top, renders it as inline-block, declares the font, specifies font-style and font-weight as normal, and sets the line height as 1. Otherwise, use -webkit-font-smoothing: antialiased and -moz-osx-font-smoothing: grayscale; for cross-browser consistency.
Then, the
width: 1em;
}
is an empty glyphicon.
There are 200 classes, each class is for an icon. The common format of these classes is as follows:
content: "hexvalue";
}
For example, the user used Icon, its class is as follows:
content: "\e008";
}
Usage
To use icons, simply use the code below. Please leave appropriate space between the icon and text.
<span class="glyphicon glyphicon-search"></span>
The following example demonstrates how to use font icons:
<html>
<head>
<title>Bootstrap 实例 - 如何使用字体图标</title>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script></head>
<body>
<p>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-sort-by-attributes"></span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-sort-by-attributes-alt"></span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-sort-by-order"></span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-sort-by-order-alt"></span>
</button>
</p>
<button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-user"></span> User
</button>
<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-user"></span> User
</button>
<button type="button" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-user"></span> User
</button>
</body>
</html>
实例
<!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 如何使用字体图标</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <body> <p> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-sort-by-attributes"></span> </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-sort-by-attributes-alt"></span> </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-sort-by-order"></span> </button> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-sort-by-order-alt"></span> </button> </p> <button type="button" class="btn btn-default btn-lg"> <span class="glyphicon glyphicon-user"></span> User </button> <button type="button" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-user"></span> User </button> <button type="button" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-user"></span> User </button> </body> </html>
Run instance »
Click the "Run instance" button to view the online instance
带有导航栏的字体图标
<html>
<head>
<title>导航栏的字体图标</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding-top: 50px;
padding-left: 50px;
}
</style>
<!--[if lt IE 9]>
<script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#"><span class="glyphicon glyphicon-home">Home</span></a></li>
<li><a href="#shop"><span class="glyphicon glyphicon-shopping-cart">Shop</span></a></li>
<li><a href="#support"><span class="glyphicon glyphicon-headphones">Support</span></a></li>
</ul>
</div><!-- /.nav-collapse -->
</div><!-- /.container -->
</div>
<!-- jQuery (Bootstrap 插件需要引入) -->
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- 包含了所有编译插件 -->
<script src="http://apps.bdimg.com/libs/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>
实例
<!DOCTYPE html> <html> <head> <title>导航栏的字形图标</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> <style> body { padding-top: 50px; padding-left: 50px; } </style> <!--[if lt IE 9]> <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script> <![endif]--> </head> <body> <div class="navbar navbar-fixed-top navbar-inverse" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Project name</a> </div> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="#"><span class="glyphicon glyphicon-home">Home</span></a></li> <li><a href="#shop"><span class="glyphicon glyphicon-shopping-cart">Shop</span></a></li> <li><a href="#support"><span class="glyphicon glyphicon-headphones">Support</span></a></li> </ul> </div><!-- /.nav-collapse --> </div><!-- /.container --> </div> <!-- jQuery (Bootstrap 插件需要引入) --> <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <!-- 包含了所有编译插件 --> <script src="http://apps.bdimg.com/libs/bootstrap/3.2.0/js/bootstrap.min.js"></script> </body> </html>
Run instance »
Click the "Run instance" button to view the online instance
定制字体图标
我们已经看到如何使用字体图标,接下来我们看看如何定制字体图标。
我们将以上面的实例开始,并通过改变字体尺寸、颜色和应用文本阴影来进行定制图标。
下面是开始的代码:
<span class="glyphicon glyphicon-user"></span> User
</button>
Customize Font Size
You can make an icon appear larger or smaller by increasing or decreasing its font size.
<span class="glyphicon glyphicon -user"></span> User
</button>
Customized font color
<span class="glyphicon glyphicon-user"></span> User
</button>
Apply text shadow
<span class="glyphicon glyphicon-user"></span> User
</button>
Online custom font icon
Icon list
<td
<t
Icon | Class name | Instance |
---|---|---|
##glyphicon glyphicon-asterisk | Try it | |
##glyphicon glyphicon-plus | Try it | |
##glyphicon glyphicon-minus | Try it||
glyphicon glyphicon-euro | Try it||
##glyphicon glyphicon-cloud Try it | ||
glyphicon glyphicon-envelopeTry it | ||
glyphicon glyphicon-pencilTry it | ||
glyphicon glyphicon-glassTry it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon -star | |
##glyphicon glyphicon-star-empty | ||
##glyphicon glyphicon-user | Try it | |
glyphicon glyphicon-film | Try it | |
##glyphicon glyphicon-th-large | Try it | |
##glyphicon glyphicon-th | Try it | |
glyphicon glyphicon-th-list | Try it | |
glyphicon glyphicon-ok | Try it | |
##glyphicon glyphicon-remove | try it | |
glyphicon glyphicon-zoom-in | Try it | |
##glyphicon glyphicon-zoom-out | Try it | |
##glyphicon glyphicon-off | Try it | |
glyphicon glyphicon-signal | Try it | |
glyphicon glyphicon-cog | Try it | |
glyphicon glyphicon-trash | Try it | |
##glyphicon glyphicon-home | Try it||
glyphicon glyphicon-file | Try it||
##glyphicon glyphicon -timeTry it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon-upload | |
##glyphicon glyphicon-inbox | ||
glyphicon glyphicon-play-circle | ||
glyphicon glyphicon-repeat | ||
##glyphicon glyphicon-refresh | Try it | |
##glyphicon glyphicon-list-alt | Try it | |
glyphicon glyphicon-lock | Try it | |
glyphicon glyphicon-flag | Try it | |
##glyphicon glyphicon-headphones | Try it | |
##glyphicon glyphicon-volume-off | Try it | |
glyphicon glyphicon-volume-down | Try it | |
##glyphicon glyphicon-volume-up | Try it | |
glyphicon glyphicon-qrcode | Try it | |
glyphicon glyphicon-barcode | Try it | |
glyphicon glyphicon-tag | Try it | |
##glyphicon glyphicon-tags | Try it | |
##glyphicon glyphicon-book | Try it||
glyphicon glyphicon-bookmark | Try it||
##glyphicon glyphicon -printTry it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon-italic | |
##glyphicon glyphicon-text-height | ||
glyphicon glyphicon-text-width | ||
glyphicon glyphicon-align-left | ||
##glyphicon glyphicon-align-center | Try it | |
##glyphicon glyphicon-align-right | Try it | |
glyphicon glyphicon-align-justify | Try it | |
glyphicon glyphicon-list | Try it | |
##glyphicon glyphicon-indent-left | try it | |
glyphicon glyphicon-indent-right | Try it | |
##glyphicon glyphicon-facetime-video | Try it | |
##glyphicon glyphicon-picture | Try it | |
glyphicon glyphicon-map-marker | Try it | |
glyphicon glyphicon-adjust | Try it | |
##glyphicon glyphicon-tint | Try it||
##glyphicon glyphicon-editTry it | ||
glyphicon glyphicon-shareTry it | ||
glyphicon glyphicon-checkTry it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon -backward | |
glyphicon glyphicon-play | ||
##glyphicon glyphicon-pause | ||
glyphicon glyphicon-stop | ||
##glyphicon glyphicon-forward | Try it | |
##glyphicon glyphicon-fast-forward | Try it | |
glyphicon glyphicon-step-forward | Try it | |
glyphicon glyphicon-eject | Try it | |
##glyphicon glyphicon-chevron-left | try it | |
glyphicon glyphicon-chevron-right | Try it | |
##glyphicon glyphicon-plus-sign | Try it | |
glyphicon glyphicon-minus-sign | Try it | |
##glyphicon glyphicon-remove-sign | Try it | |
glyphicon glyphicon-ok-sign | Try it | |
##glyphicon glyphicon-question -sign | Try it||
glyphicon glyphicon-info-sign | Try it||
##glyphicon glyphicon-screenshotTry it | ||
glyphicon glyphicon-remove-circleTry it | ||
Try it | ||
Try it | ##glyphicon glyphicon-arrow-left | |
glyphicon glyphicon-arrow-right | ||
##glyphicon glyphicon -arrow-up | ||
##glyphicon glyphicon-arrow-down | Try it | |
##glyphicon glyphicon-share-alt | Try it | |
glyphicon glyphicon-resize-full | Try it | |
glyphicon glyphicon-resize-small | Try it | |
##glyphicon glyphicon-exclamation-sign | Try it | |
##glyphicon glyphicon-gift | Try it | |
glyphicon glyphicon-leaf | Try it | |
glyphicon glyphicon-fire | Try it | |
##glyphicon glyphicon-eye-open | Try it | |
##glyphicon glyphicon-eye-close | Try it | |
glyphicon glyphicon-warning-sign | Try it | |
glyphicon glyphicon-plane | Try it | |
##glyphicon glyphicon-calendar | Try it||
##glyphicon glyphicon-randomTry it | ||
glyphicon glyphicon-commentTry it | ||
glyphicon glyphicon-magnetTry it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon -shopping-cart | |
##glyphicon glyphicon-folder-close | ||
##glyphicon glyphicon-folder-open | Try it | |
glyphicon glyphicon-resize-vertical | Try it | |
## glyphicon glyphicon-resize-horizontal | Try it | |
glyphicon glyphicon-hdd | Try it | |
##glyphicon glyphicon-bullhorn | Try it | |
glyphicon glyphicon-bell | Try it | |
##glyphicon glyphicon-certificate | try it | |
glyphicon glyphicon-thumbs-up | Try it | |
##glyphicon glyphicon-thumbs-down | Try it | |
##glyphicon glyphicon-hand-right | Try it | |
##glyphicon glyphicon-hand-left | Try it||
glyphicon glyphicon-hand-up | Try it||
##glyphicon glyphicon-hand -downTry it | ||
glyphicon glyphicon-circle-arrow-rightTry it | ||
Try it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon-wrench | |
glyphicon glyphicon-tasks | ||
##glyphicon glyphicon-filter | ||
##glyphicon glyphicon-briefcase | Try it | |
##glyphicon glyphicon-fullscreen | Try it | |
glyphicon glyphicon-dashboard | Try it | |
##glyphicon glyphicon-paperclip | Try it | |
##glyphicon glyphicon-heart-empty | Try it | |
glyphicon glyphicon-link | Try it | |
glyphicon glyphicon-phone | Try it | |
glyphicon glyphicon-pushpin | Try it | |
##glyphicon glyphicon-usd | Try it | |
##glyphicon glyphicon-gbp | Try it | |
glyphicon glyphicon-sort | Try it | |
glyphicon glyphicon-sort-by-alphabet | Try it | |
glyphicon glyphicon-sort-by-alphabet-alt | Try it | |
##glyphicon glyphicon-sort-by-order | Try it||
##glyphicon glyphicon-sort-by-order-altTry it | ||
glyphicon glyphicon-sort-by-attributesTry it | ||
glyphicon glyphicon-sort-by-attributes-altTry it | ||
Try it | ||
Try it | ||
Try it | ||
Try it | ##glyphicon glyphicon-log-in | |
##glyphicon glyphicon-flash | ||
glyphicon glyphicon-log-out | ||
glyphicon glyphicon-new-window | ||
##glyphicon glyphicon-record | Try it | |
##glyphicon glyphicon-save | Try it | |
glyphicon glyphicon-open | Try it | |
glyphicon glyphicon-saved | Try it | |