Bootstarp學習(六)表徵圖,bootstarp學習表徵圖
表徵圖(一)
200個icon:
這裡說的表徵圖就是Web製作中常看到的小icon表徵圖,可以說這些小icon表徵圖是一個優秀Web中不可缺少的一部分,起到畫龍點睛的效果。在Bootstrap架構中也為大家提供了近200個不同的icon圖片,而這些表徵圖都是使用CSS3的@font-face屬性配合字型來實現的icon效果。
放心使用:
在具體介紹Bootstrap的icon表徵圖之前,我們首先要感謝glyphicons.com網站,因為Bootstrap架構中表徵圖都是glyphicons.com這個商業網站提供的,並且免費授權給Bootstrap架構使用,所以大家可以放心使用在自己的項目當中。
Bootstrap架構將內部樣式也提取出來:
1、LESS版本:對應源檔案為glyphicons.less檔案
2、Sass版本:對應源檔案為_glyphicons.scss檔案
3、編譯後的Bootstrap版本:查看bootstrap.css檔案第2375行~第2992行
原理分析:
Bootstrap架構中的表徵圖都是字型表徵圖,其實現原理就是通過@font-face屬性載入了字型。
/*源碼請查看bootstrap.css檔案第2357行~第2380行*/
@font-face {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');}
大家或許會問,這些字型我去哪裡擷取。如果你是從前面一直閱讀過來,我們在介紹檔案結構那一節就已介紹過。在Bootstrap架構中有一個fonts的目錄,這個目錄中提供的字型檔就是用於製作icon的字型檔。
自訂完字型之後,需要對icon設定一個預設樣式,在Bootstrap架構中是通過給元素添加“glyphicon”類名來實現,然後通過虛擬元素“:before”的“content”屬性調取對應的icon編碼:
/*源碼請查看bootstrap.css檔案第2381行~第2992行*/
.glyphicon {position: relative;top: 1px;display: inline-block;font-family: 'Glyphicons Halflings';font-style: normal;font-weight: normal;line-height: 1; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;}.glyphicon-asterisk:before {content: "\2a";}….
<span class="glyphicon glyphicon-search"></span><span class="glyphicon glyphicon-asterisk"></span><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-cloud"></span>
表徵圖(二)
在網頁中使用表徵圖也非常的簡單,在任何內嵌元素上應用所對應的樣式即可:
<span class="glyphicon glyphicon-search"></span><span class="glyphicon glyphicon-asterisk"></span><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-cloud"></span>
運行效果如下或查看右側結果視窗:
所有icon都是以”glyphicon-”首碼的類名開始,然後尾碼表示表徵圖的名稱。具體說明如下:
所有名稱查看:
請點擊:http://getbootstrap.com/components/#glyphicons 連結查閱或根據bootstrap.css檔案第2393行~第2992行查閱。
特別說明:
除了使用glyphicon.com提供的表徵圖之外,還可以使用第三方為Bootstrap架構設計的表徵圖字型,如Font Awesome(http://www.bootcss.com/p/font-awesome/)。使用方法和上面介紹的一樣,不過記得將字型下載到你本地。 感興趣的可以閱讀官網相關介紹。
<span class="glyphicon glyphicon-search"></span><span class="glyphicon glyphicon-asterisk"></span><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-cloud"></span>