本章节将讲解字体图标(Glyphicons),并通过一些实例了解它的使用。Bootstrap 捆绑了 200 多种字体格式的字形。首先让我们先来理解一下什么是字体图标。
什么是字体图标?
字体图标是在 Web 项目中使用的图标字体。虽然,Glyphicons Halflings 需要商业许可,但是您可以通过基于项目的 Bootstrap 来免费使用这些图标。
为了表示对图标作者的感谢,希望您在使用时加上 GLYPHICONS 网站的链接。
获取字体图标
我们已经在 环境安装 章节下载了 Bootstrap 3.x 版本,并理解了它的目录结构。在 fonts 文件夹内可以找到字体图标,它包含了下列这些文件:
- glyphicons-halflings-regular.eot
- glyphicons-halflings-regular.svg
- glyphicons-halflings-regular.ttf
- glyphicons-halflings-regular.woff
相关的 CSS 规则写在 dist 文件夹内的 css 文件夹内的 bootstrap.css 和 bootstrap-min.css 文件上。
CSS 规则解释
下面的 CSS 规则构成 glyphicon class。
所以 font-face 规则实际上是在找到 glyphicons 地方声明 font-family 和位置。
.glyphicon class 声明一个从顶部偏移 1px 的相对位置,呈现为 inline-block,声明字体,规定 font-style 和 font-weight 为 normal,设置行高为 1。除此之外,使用 -webkit-font-smoothing: antialiased 和 -moz-osx-font-smoothing: grayscale; 获得跨浏览器的一致性。
然后,这里的
.glyphicon:empty { width: 1em; }
是空的 glyphicon。
这里有 200 个 class,每个 class 针对一个图标。这些 class 的常见格式如下:
.glyphicon-keyword:before { content: "hexvalue"; }
比如,使用的 user 图标,它的 class 如下:
.glyphicon-user:before { content: "e008"; }
用法
如需使用图标,只需要简单地使用下面的代码即可。请在图标和文本之间保留适当的空间。
<span class="glyphicon glyphicon-search"></span>
下面的实例演示了如何使用字体图标:
实例
结果如下所示:
带有字体图标的导航栏
实例
定制字体图标
我们已经看到如何使用字体图标,接下来我们看看如何定制字体图标。
我们将以上面的实例开始,并通过改变字体尺寸、颜色和应用文本阴影来进行定制图标。
下面是开始的代码:
<button type="button" class="btn btn-primary btn-lg"> <span class="glyphicon glyphicon-user"></span> User </button>
定制字体尺寸
通过增加或减少图标的字体尺寸,您可以让图标看起来更大或更小。
<button type="button" class="btn btn-primary btn-lg" style="font-size: 60px"> <span class="glyphicon glyphicon-user"></span> User </button>
定制字体颜色
<button type="button" class="btn btn-primary btn-lg" style="color: rgb(212, 106, 64);"> <span class="glyphicon glyphicon-user"></span> User </button>
应用文本阴影
<button type="button" class="btn btn-primary btn-lg" style="text-shadow: black 5px 3px 3px;"> <span class="glyphicon glyphicon-user"></span> User </button>
在线定制字体图标
图标列表
图标 | 类名 | 实例 |
---|---|---|
glyphicon glyphicon-asterisk | 运行代码 | |
glyphicon glyphicon-plus | 运行代码 | |
glyphicon glyphicon-minus | 运行代码 | |
glyphicon glyphicon-euro | 运行代码 | |
glyphicon glyphicon-cloud | 运行代码 | |
glyphicon glyphicon-envelope | 运行代码 | |
glyphicon glyphicon-pencil | 运行代码 | |
glyphicon glyphicon-glass | 运行代码 | |
glyphicon glyphicon-music | 运行代码 | |
glyphicon glyphicon-search | 运行代码 | |
glyphicon glyphicon-heart | 运行代码 | |
glyphicon glyphicon-star | 运行代码 | |
glyphicon glyphicon-star-empty | 运行代码 | |
glyphicon glyphicon-user | 运行代码 | |
glyphicon glyphicon-film | 运行代码 | |
glyphicon glyphicon-th-large | 运行代码 | |
glyphicon glyphicon-th | 运行代码 | |
glyphicon glyphicon-th-list | 运行代码 | |
glyphicon glyphicon-ok | 运行代码 | |
glyphicon glyphicon-remove | 运行代码 | |
glyphicon glyphicon-zoom-in | 运行代码 | |
glyphicon glyphicon-zoom-out | 运行代码 | |
glyphicon glyphicon-off | 运行代码 | |
glyphicon glyphicon-signal | 运行代码 | |
glyphicon glyphicon-cog | 运行代码 | |
glyphicon glyphicon-trash | 运行代码 | |
glyphicon glyphicon-home | 运行代码 | |
glyphicon glyphicon-file | 运行代码 | |
glyphicon glyphicon-time | 运行代码 | |
glyphicon glyphicon-road | 运行代码 | |
glyphicon glyphicon-download-alt | 运行代码 | |
glyphicon glyphicon-download | 运行代码 | |
glyphicon glyphicon-upload | 运行代码 | |
glyphicon glyphicon-inbox | 运行代码 | |
glyphicon glyphicon-play-circle | 运行代码 | |
glyphicon glyphicon-repeat | 运行代码 | |
glyphicon glyphicon-refresh | 运行代码 | |
glyphicon glyphicon-list-alt | 运行代码 | |
glyphicon glyphicon-lock | 运行代码 | |
glyphicon glyphicon-flag | 运行代码 | |
glyphicon glyphicon-headphones | 运行代码 | |
glyphicon glyphicon-volume-off | 运行代码 | |
glyphicon glyphicon-volume-down | 运行代码 | |
glyphicon glyphicon-volume-up | 运行代码 | |
glyphicon glyphicon-qrcode | 运行代码 | |
glyphicon glyphicon-barcode | 运行代码 | |
glyphicon glyphicon-tag | 运行代码 | |
glyphicon glyphicon-tags | 运行代码 | |
glyphicon glyphicon-book | 运行代码 | |
glyphicon glyphicon-bookmark | 运行代码 | |
glyphicon glyphicon-print | 运行代码 | |
glyphicon glyphicon-camera | 运行代码 | |
glyphicon glyphicon-font | 运行代码 | |
glyphicon glyphicon-bold | 运行代码 | |
glyphicon glyphicon-italic | 运行代码 | |
glyphicon glyphicon-text-height | 运行代码 | |
glyphicon glyphicon-text-width | 运行代码 | |
glyphicon glyphicon-align-left | 运行代码 | |
glyphicon glyphicon-align-center | 运行代码 | |
glyphicon glyphicon-align-right | 运行代码 | |
glyphicon glyphicon-align-justify | 运行代码 | |
glyphicon glyphicon-list | 运行代码 | |
glyphicon glyphicon-indent-left | 运行代码 | |
glyphicon glyphicon-indent-right | 运行代码 | |
glyphicon glyphicon-facetime-video | 运行代码 | |
glyphicon glyphicon-picture | 运行代码 | |
glyphicon glyphicon-map-marker | 运行代码 | |
glyphicon glyphicon-adjust | 运行代码 | |
glyphicon glyphicon-tint | 运行代码 | |
glyphicon glyphicon-edit | 运行代码 | |
glyphicon glyphicon-share | 运行代码 | |
glyphicon glyphicon-check | 运行代码 | |
glyphicon glyphicon-move | 运行代码 | |
glyphicon glyphicon-step-backward | 运行代码 | |
glyphicon glyphicon-fast-backward | 运行代码 | |
glyphicon glyphicon-backward | 运行代码 | |
glyphicon glyphicon-play | 运行代码 | |
glyphicon glyphicon-pause | 运行代码 | |
glyphicon glyphicon-stop | 运行代码 | |
glyphicon glyphicon-forward | 运行代码 | |
glyphicon glyphicon-fast-forward | 运行代码 | |
glyphicon glyphicon-step-forward | 运行代码 | |
glyphicon glyphicon-eject | 运行代码 | |
glyphicon glyphicon-chevron-left | 运行代码 | |
glyphicon glyphicon-chevron-right | 运行代码 | |
glyphicon glyphicon-plus-sign | 运行代码 | |
glyphicon glyphicon-minus-sign | 运行代码 | |
glyphicon glyphicon-remove-sign | 运行代码 | |
glyphicon glyphicon-ok-sign | 运行代码 | |
glyphicon glyphicon-question-sign | 运行代码 | |
glyphicon glyphicon-info-sign | 运行代码 | |
glyphicon glyphicon-screenshot | 运行代码 | |
glyphicon glyphicon-remove-circle | 运行代码 | |
glyphicon glyphicon-ok-circle | 运行代码 | |
glyphicon glyphicon-ban-circle | 运行代码 | |
glyphicon glyphicon-arrow-left | 运行代码 | |
glyphicon glyphicon-arrow-right | 运行代码 | |
glyphicon glyphicon-arrow-up | 运行代码 | |
glyphicon glyphicon-arrow-down | 运行代码 | |
glyphicon glyphicon-share-alt | 运行代码 | |
glyphicon glyphicon-resize-full | 运行代码 | |
glyphicon glyphicon-resize-small | 运行代码 | |
glyphicon glyphicon-exclamation-sign | 运行代码 | |
glyphicon glyphicon-gift | 运行代码 | |
glyphicon glyphicon-leaf | 运行代码 | |
glyphicon glyphicon-fire | 运行代码 | |
glyphicon glyphicon-eye-open | 运行代码 | |
glyphicon glyphicon-eye-close | 运行代码 | |
glyphicon glyphicon-warning-sign | 运行代码 | |
glyphicon glyphicon-plane | 运行代码 | |
glyphicon glyphicon-calendar | 运行代码 | |
glyphicon glyphicon-random | 运行代码 | |
glyphicon glyphicon-comment | 运行代码 | |
glyphicon glyphicon-magnet | 运行代码 | |
glyphicon glyphicon-chevron-up | 运行代码 | |
glyphicon glyphicon-chevron-down | 运行代码 | |
glyphicon glyphicon-retweet | 运行代码 | |
glyphicon glyphicon-shopping-cart | 运行代码 | |
glyphicon glyphicon-folder-close | 运行代码 | |
glyphicon glyphicon-folder-open | 运行代码 | |
glyphicon glyphicon-resize-vertical | 运行代码 | |
glyphicon glyphicon-resize-horizontal | 运行代码 | |
glyphicon glyphicon-hdd | 运行代码 | |
glyphicon glyphicon-bullhorn | 运行代码 | |
glyphicon glyphicon-bell | 运行代码 | |
glyphicon glyphicon-certificate | 运行代码 | |
glyphicon glyphicon-thumbs-up | 运行代码 | |
glyphicon glyphicon-thumbs-down | 运行代码 | |
glyphicon glyphicon-hand-right | 运行代码 | |
glyphicon glyphicon-hand-left | 运行代码 | |
glyphicon glyphicon-hand-up | 运行代码 | |
glyphicon glyphicon-hand-down | 运行代码 | |
glyphicon glyphicon-circle-arrow-right | 运行代码 | |
glyphicon glyphicon-circle-arrow-left | 运行代码 | |
glyphicon glyphicon-circle-arrow-up | 运行代码 | |
glyphicon glyphicon-circle-arrow-down | 运行代码 | |
glyphicon glyphicon-globe | 运行代码 | |
glyphicon glyphicon-wrench | 运行代码 | |
glyphicon glyphicon-tasks | 运行代码 | |
glyphicon glyphicon-filter | 运行代码 | |
glyphicon glyphicon-briefcase | 运行代码 | |
glyphicon glyphicon-fullscreen | 运行代码 | |
glyphicon glyphicon-dashboard | 运行代码 | |
glyphicon glyphicon-paperclip | 运行代码 | |
glyphicon glyphicon-heart-empty | 运行代码 | |
glyphicon glyphicon-link | 运行代码 | |
glyphicon glyphicon-phone | 运行代码 | |
glyphicon glyphicon-pushpin | 运行代码 | |
glyphicon glyphicon-usd | 运行代码 | |
glyphicon glyphicon-gbp | 运行代码 | |
glyphicon glyphicon-sort | 运行代码 | |
glyphicon glyphicon-sort-by-alphabet | 运行代码 | |
glyphicon glyphicon-sort-by-alphabet-alt | 运行代码 | |
glyphicon glyphicon-sort-by-order | 运行代码 | |
glyphicon glyphicon-sort-by-order-alt | 运行代码 | |
glyphicon glyphicon-sort-by-attributes | 运行代码 | |
glyphicon glyphicon-sort-by-attributes-alt | 运行代码 | |
glyphicon glyphicon-unchecked | 运行代码 | |
glyphicon glyphicon-expand | 运行代码 | |
glyphicon glyphicon-collapse-down | 运行代码 | |
glyphicon glyphicon-collapse-up | 运行代码 | |
glyphicon glyphicon-log-in | 运行代码 | |
glyphicon glyphicon-flash | 运行代码 | |
glyphicon glyphicon-log-out | 运行代码 | |
glyphicon glyphicon-new-window | 运行代码 | |
glyphicon glyphicon-record | 运行代码 | |
glyphicon glyphicon-save | 运行代码 | |
glyphicon glyphicon-open | 运行代码 | |
glyphicon glyphicon-saved | 运行代码 | |
glyphicon glyphicon-import | 运行代码 | |
glyphicon glyphicon-export | 运行代码 | |
glyphicon glyphicon-send | 运行代码 | |
glyphicon glyphicon-floppy-disk | 运行代码 | |
glyphicon glyphicon-floppy-saved | 运行代码 | |
glyphicon glyphicon-floppy-remove | 运行代码 | |
glyphicon glyphicon-floppy-save | 运行代码 | |
glyphicon glyphicon-floppy-open | 运行代码 | |
glyphicon glyphicon-credit-card | 运行代码 | |
glyphicon glyphicon-transfer | 运行代码 | |
glyphicon glyphicon-cutlery | 运行代码 | |
glyphicon glyphicon-header | 运行代码 | |
glyphicon glyphicon-compressed | 运行代码 | |
glyphicon glyphicon-earphone | 运行代码 | |
glyphicon glyphicon-phone-alt | 运行代码 | |
glyphicon glyphicon-tower | 运行代码 | |
glyphicon glyphicon-stats | 运行代码 | |
glyphicon glyphicon-sd-video | 运行代码 | |
glyphicon glyphicon-hd-video | 运行代码 | |
glyphicon glyphicon-subtitles | 运行代码 | |
glyphicon glyphicon-sound-stereo | 运行代码 | |
glyphicon glyphicon-sound-dolby | 运行代码 | |
glyphicon glyphicon-sound-5-1 | 运行代码 | |
glyphicon glyphicon-sound-6-1 | 运行代码 | |
glyphicon glyphicon-sound-7-1 | 运行代码 | |
glyphicon glyphicon-copyright-mark | 运行代码 | |
glyphicon glyphicon-registration-mark | 运行代码 | |
glyphicon glyphicon-cloud-download | 运行代码 | |
glyphicon glyphicon-cloud-upload | 运行代码 | |
glyphicon glyphicon-tree-conifer | 运行代码 | |
glyphicon glyphicon-tree-deciduous | 运行代码 |