Bootstrap 字体图标 ( Glyphicons )

Bootstrap 3 内置了字体图标(Glyphicons) ,本章我们将学习如何使用这些字体图标

什么是字体图标?

字体图标是在 Web 项目中使用的图标字体

获取字体图标

我们已经在 环境安装 章节下载了 Bootstrap 3.x 版本,并理解了它的目录结构

可以在 fonts 文件夹内可以找到字体图标,它包含了下列这些文件

  • glyphicons-halflings-regular.eot
  • glyphicons-halflings-regular.svg
  • glyphicons-halflings-regular.ttf
  • glyphicons-halflings-regular.woff

字体图标列表

点击这里,查看可用的字体图标列表

用法

如何使用图标?

只需要简单地使用下面的代码即可

注意: 请在图标和文本之间保留适当的空间

<span class="glyphicon glyphicon-search"></span>

下面的范例演示了如何使用字体图标

<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>

运行范例 »

运行以上范例,输出结果如下

如何使用字体图标

带有字体图标的导航栏

我们可以给导航栏添加一些图标

<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>
    </div>
</div>

运行范例 »

运行以上范例,输出结果如下

如何使用字体图标

定制字体图标

经过上面范例的操练,我们已经知道了如何使用字体图标

接下来我们看看如何定制字体图标

我们可以通过改变字体尺寸、颜色和应用文本阴影来进行定制图标

<button type="button" class="btn btn-primary btn-lg">
  <span class="glyphicon glyphicon-user"></span> User
</button>

效果如下所示

定制字体尺寸

可以通过 CSS font-size 属性来增加或减少图标的字体尺寸,让图标看起来更大或更小

<button type="button" class="btn btn-primary btn-lg" style="font-size: 60px">
  <span class="glyphicon glyphicon-user"></span> User
</button>

定制字体颜色

可以通过 CSS color 属性来定制图标字体的颜色

<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 运行范例 »
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.