Bootstrap 字體圖標
本章將講解字體圖示(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-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_halflings/glyphicons-halflings-regular.svg#glyphicons_halings/glyphicons-halflings-regular.svg#glyregular') format('svg');
}
.glyphicon {
position: relative;
top: 1px;
display: inline-block;
font-family: display: inline-block;
font-family: display: inline-block;
'Glyphicons Halflings';
-webkit-font-smoothing: antialiased;
font-style: normal;
font-weight: normal;
line-height: font-weight: normal;
所以 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; 取得跨瀏覽器的一致性。
然後,這裡的
width: 1em;
}
#是空的 glyphicon。
這裡有 200 個 class,每個 class 針對一個圖示。這些class 的常見格式如下:
content: "hexvalue";
}
#例如,使用的user圖標,它的class 如下:
content: "\e008";
}
用法
如需使用圖標,只需要簡單地使用下面的程式碼即可。請在圖示和文字之間保留適當的空間。
<span class="glyphicon glyphicon-search"></span>
下面的實例示範如何使用字體圖示:
<連結href="http: //libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/ bootstrap.min.js" ></script></head>
<body>
<p>
<按鈕類型=「按鈕」類別=「btn」 btn-default">
<按鈕 ## </button>
#
</button>
</p>
<button type="button" class ="btn btn-default btn-lg">
</button>
<按鈕類型=“按鈕”class=“btn btn-default btn-sm”>
使用者
</button>
<按鈕類型=“按鈕”class=“btn btn-default btn-xs”>
使用者
</button>
</body>
</html>
執行實例 »
點擊 "執行實例" 按鈕查看線上實例
##有導覽列的字型圖示
/apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<樣式>
body {
<樣式>
body {
## padding-left: 50px;
}
;
# button" class="navbar-toggle" data-toggle="collapse" data-target=" .navbar-collapse">
span class="icon-bar">
< ;a class="navbar-brand" href="#">專案名稱
<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>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>
執行實例 »
點擊 "執行實例" 按鈕查看線上實例
定制字体图标
我们已经看到如何使用字体图标,接下来我们看看如何定制字体图标。
我们将以上面的实例开始,并通过改变字体尺寸、颜色和应用文本阴影来进行定制图标。
下面是开始的代码:
<span class="glyphicon glyphicon-user"></span> User
</button>
定製字體尺寸
透過增加或減少圖示的字體尺寸,您可以讓圖示看起來更大或更小。
<span class="glyphicon glyphicon -user"></span> User
</button>
線上定製字體圖示
圖示清單
<td
<t
圖示 | 類別名稱 | 實例 |
---|---|---|
#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-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-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-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-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-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-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-collapse-down試試看 | ||
glyphicon glyphicon-collapse-up試試看 | ||
試試看 | ||
試試看 | ||
試試看 | ||
試試看#################glyphicon glyphicon-record## ####試試看########################glyphicon glyphicon-save######試試看######### ################glyphicon glyphicon-open#######試試看################################################# | glyphicon glyphicon-saved | 嘗試 |