詳解Bootstrap glyphicons字體圖標(biāo)
本章將講解字體圖標(biāo)(Glyphicons),并通過一些實(shí)例了解它的使用。Bootstrap 捆綁了 200 多種字體格式的字形。首先讓我們先來理解一下什么是字體圖標(biāo)。
首先給大家介紹什么是字體圖標(biāo):
字體圖標(biāo)是在 Web 項(xiàng)目中使用的圖標(biāo)字體。字體圖標(biāo)在下載的Bootstrap的fonts文件夾中。
.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;
}
.glyphicon class 聲明一個從頂部偏移 1px 的相對位置,呈現(xiàn)為 inline-block,聲明字體,規(guī)定 font-style 和 font-weight 為 normal,設(shè)置行高為 1。除此之外,使用-webkit-font-smoothing: antialiased 和 -moz-osx-font-smoothing: grayscale; 獲得跨瀏覽器的一致性。
關(guān)于-webkit-font-smoothing和-moz-osx-font-smoothing:
-webkit-font-smoothing屬性。這個屬性可以使頁面上的字體抗鋸齒,使用后字體看起來會更清晰舒服。
none ------ 對低像素的文本比較好
subpixel-antialiased ------默認(rèn)值
antialiased ------抗鋸齒很好
auto
inherit ------繼承父元素
initial
-moz-osx-font-smoothing屬性,其中-osx-表明這是mozilla難得的給特定操作系統(tǒng)推出的特性增強(qiáng),由于缺乏文檔,目前已知的取值是:
grayscale ------抗鋸齒很好
auto ------默認(rèn)值
inherit ------繼承
Bootstrap提供了200個字體圖標(biāo),每個圖標(biāo)對應(yīng)一個class,在使用時,我們只需要包含glyphicon和對應(yīng)的class即可。
使用方法:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>demo</title>
<link href="bootstrap-3.3.4-dist/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
body{padding: 20px;}
</style>
</head>
<body>
<span class = "glyphicon glyphicon-lock"></span>
<span class = "glyphicon glyphicon-lock" style = "font-size:30px;"></span>
<span class = "glyphicon glyphicon-lock" style = "font-size:60px;"></span>
</body>
</html>

配合button使用:
<body>
<button class="btn btn-default">
<span class = "glyphicon glyphicon-home"></span>
</button>
<button class="btn btn-success">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-info">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-warning">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-warning btn-lg">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-warning btn-sm">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
</body>
效果:

定制字體圖標(biāo)
在上一個例中,其實(shí)我們已經(jīng)實(shí)現(xiàn)了對字體圖標(biāo)大小和顏色的定制,此處再做進(jìn)一步說明。
通過改變字體的大小或button的大小,可以改變字體圖標(biāo)的大小。
通過設(shè)置color的顏色,可以改變字體圖標(biāo)的顏色,如下:
<body>
<button class="btn btn-success">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-success" style="color:#FF0000;">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-success">
<span class = "glyphicon glyphicon-home" style="color:#FF0000;"></span> Home
</button>
</body>
效果:

可以看出:通過改變其父元素或者是span本身的color,都可以改變字體圖標(biāo)的顏色。
應(yīng)用文本陰影
<body>
<button class="btn btn-success">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-success btn-lg" style="text-shadow: black 3px 2px 3px;">
<span class = "glyphicon glyphicon-home"></span> Home
</button>
<button class="btn btn-success btn-lg">
<span class = "glyphicon glyphicon-home" style="text-shadow: black 3px 2px 3px;"></span> Home
</button>
</body>

更多請查看字體圖標(biāo),可以bootstrap官方文檔:

以上內(nèi)容給大家介紹了Bootstrap glyphicons字體圖標(biāo)的相關(guān)知識,希望大家喜歡。
- 本地Bootstrap文件字體圖標(biāo)引入?yún)s無法顯示問題的解決方法
- Bootstrap字體圖標(biāo)無法正常顯示的解決方法
- BootStrap glyphicon圖標(biāo)無法顯示的解決方法
- Bootstrap3 input輸入框插入glyphicon圖標(biāo)的方法
- bootstrap布局中input輸入框右側(cè)圖標(biāo)點(diǎn)擊功能
- BootStrap glyphicons 字體圖標(biāo)實(shí)現(xiàn)方法
- JS組件系列之Bootstrap Icon圖標(biāo)選擇組件
- 很不錯的兩款Bootstrap Icon圖標(biāo)選擇組件
- bootstrap中添加額外的圖標(biāo)實(shí)例代碼
相關(guān)文章
JavaScript遍歷table表格中的某行某列并打印其值
這篇文章主要介紹了JavaScript遍歷table表格中的某行某列并打印其值,需要的朋友可以參考下2014-07-07
深入理解JavaScript是如何實(shí)現(xiàn)繼承的
這篇文章主要介紹了JavaScript是如何實(shí)現(xiàn)繼承的,有需要的朋友可以參考一下2013-12-12
一文徹底理解js原生語法prototype,__proto__和constructor
作為一名前端工程師,必須搞懂JS中的prototype、__proto__與constructor屬性,相信很多初學(xué)者對這些屬性存在許多困惑,容易把它們混淆,下面這篇文章主要給大家介紹了關(guān)于js原生語法prototype,__proto__和constructor的相關(guān)資料,需要的朋友可以參考下2021-10-10
js彈出層包含flash 不能關(guān)閉隱藏的2種處理方法
js彈出層包含flash 不能關(guān)閉隱藏的2種處理方法,需要的朋友可以參考一下2013-06-06
js中for...in循環(huán)對象時輸出key值順序混亂問題解決
很久之前就有前輩告訴我用for...in循環(huán)對象屬性的順序不是固定的,xiam?這篇文章主要給大家介紹了關(guān)于js中for...in循環(huán)對象時輸出key值順序混亂問題解決方法,需要的朋友可以參考下2023-11-11

