将Font Awesome 集成到 Bootstrap 非常容易,还可以被单独使用。

最简单的 Bootstrap + Font Awesome 集成方式

使用这种方式将 Font Awesome 集成到默认的 Bootstrap CSS中。

  1. 拷贝 Font Awesome 字体目录到你的项目中。
  2. font-awesome.min.css 文件到你的项目中。
  3. 打开你的项目中的 font-awesome.min.css 文件并编辑字体路径指向正确的位置。

    字体路径是相对于你的 CSS 目录的。

  4. 在html文档中的 <head> 部分,引入 font-awesome.min.css 文件。
    1. <link rel="stylesheet" href="../css/bootstrap.min.css">
    2. <link rel="stylesheet" href="../css/font-awesome.min.css">
  5. 在浏览器中打开页面,检查是否正确启用了 Font Awesome!

自定义 Bootstrap + Font Awesome LESS文件的方式进行集成

修改Bootstrap的LESS文件以集成 Font Awesome。

  1. 拷贝 Font Awesome 字体目录到你的项目中。
  2. 拷贝 font-awesome.less 文件到 bootstrap/less 目录。
  3. 打开 bootstrap.less 文件,并将 @import "sprites.less"; 替换为 @import "font-awesome.less";
  4. 打开你的项目中的 font-awesome.less 文件,并编辑 @FontAwesomePath 变量,将其值替换为指向字体文件的正确路径。
    1. @FontAwesomePath: "../font";

    字体路径相对于存放编译之后的CSS文件的目录。

  5. 重新编译Bootstrap的所有 LESS 文件。如果你使用的是less.js脚本动态编译的话就能直接在浏览器中看到效果了。
  6. 在浏览器中打开页面,检查是否正确启用了 Font Awesome!

自定义 Bootstrap + Font Awesome 集成,并使用 SASS 或 SCSS

我也从未使用过SASS或SCSS,如果源码包中的SCSS或SASS文件有问题的话请通知我。

不使用 Bootstrap?

Font Awesome works just as well without Twitter Bootstrap.

  1. Copy the Font Awesome font directory into your project.
  2. Copy font-awesome.less or font-awesome.min.css into your project.
  3. Open your project's font-awesome.less or font-awesome.min.css and edit the font location to point it to your font directory (see above examples).
  4. Check out the examples to start using Font Awesome!

需要支持 IE7 浏览器?

Font Awesome supports IE7. If you need it, you have my condolences.

  1. Get Font Awesome working properly in a modern browser.
  2. Copy font-awesome-ie7.min.css into your project.
  3. In the <head> of your html, reference the location to your font-awesome-ie7.min.css.
    1. <link rel="stylesheet" href="../css/bootstrap.min.css">
    2. <link rel="stylesheet" href="../css/font-awesome.min.css">
    3. <!--[if IE 7]>
    4. <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css">
    5. <![endif]-->
  4. Go complain to whoever decided your project needs IE7 support.

案例

下面的案例大部分都是重用 Bootstrap 文档中的案例。

Use Font Awesome icons in:

  • Bulleted lists (like this one)
  • Buttons
  • Button groups
  • Navigation
  • Prepended form inputs
  • And many more with Custom CSS
   
 
 
 

New Styles in 3.0

Use a few of the new styles together, and you've got easy pull quotes or a great introductory article image. Or spinning icons for loading and refreshing content. Or fun big icons in multi-line buttons. Lots of new possibilities.
Spinner icon when loading content...

HTML实例

Inline Icons

Place Font Awesome icons just about anywhere with the <i> tag.

 icon-camera-retro
  1. <i class="icon-camera-retro"></i> icon-camera-retro
 Icon classes are echoed via CSS :before.

更大的图标

通过给图标设置icon-largeicon-2x、 icon-3x或 icon-4x 样式,可以让图标相对于它所在的容器变得更大。

通过应用 icon-large (增大 33%), icon-2xicon-3x 或 icon-4x 样式让图标变得更大。

icon-camera-retro

icon-camera-retro

icon-camera-retro

icon-camera-retro

  1. <p><i class="icon-camera-retro icon-large"></i> icon-camera-retro</p>
  2. <p><i class="icon-camera-retro icon-2x"></i> icon-camera-retro</p>
  3. <p><i class="icon-camera-retro icon-3x"></i> icon-camera-retro</p>
  4. <p><i class="icon-camera-retro icon-4x"></i> icon-camera-retro</p>
 If your icons are getting chopped off on top and bottom, make sure you have sufficient line-height.

Animated Spinner

Use the icon-spin class to get any icon to rotate. Works best withicon-spinner and icon-refresh.

 Spinner icon when loading content...
  1. <i class="icon-spinner icon-spin"></i> Spinner icon when loading content...

CSS3 animations aren't supported in IE7 - IE9.

 

Bordered & Pulled Icons

Use icon-border and pull-rightor pull-left for easy pull quotes or article graphics.

Use a few of the new styles together, and you've got easy pull quotes or a great introductory article image. Or spinning icons for loading and refreshing content. Or fun big icons in multi-line buttons. You can combine all of them in any combination to get lots of new possibilities.
  1. <i class="icon-quote-left icon-4x pull-left icon-muted"></i>
  2. Use a few of the new styles together ... lots of new possibilities.
Use a few of the new styles together, and you've got easy pull quotes or a great introductory article image. Or spinning icons for loading and refreshing content. Or fun big icons in multi-line buttons. You can combine all of them in any combination to get lots of new possibilities.
  1. <i class="icon-flag icon-4x pull-left icon-border"></i>
  2. Use a few of the new styles together ... lots of new possibilities.

按钮

Font Awesome 图标能够很好的应用于按钮组件中。将图标设置的再大也可以,Bootstrap中的 pull-rightpull-left 和 icon-spin 样式都可以应用到图标上。

  1. <a class="btn" href="#">
  2. <i class="icon-repeat"></i> Reload</a>
  3. <a class="btn btn-success" href="#">
  4. <i class="icon-shopping-cart icon-large"></i> Checkout</a>
  5. <a class="btn btn-large btn-primary" href="#">
  6. <i class="icon-comment"></i> Comment</a>
  7. <a class="btn btn-small btn-info" href="#">
  8. <i class="icon-info-sign"></i> Info</a>
  9. <a class="btn btn-danger" href="#">
  10. <i class="icon-trash icon-large"></i> Delete</a>
  11. <a class="btn btn-small" href="#">
  12. <i class="icon-cog"></i> Settings</a>
  13. <a class="btn btn-large btn-danger" href="#">
  14. <i class="icon-flag icon-2x pull-left"></i>Font Awesome<br>Version 3.0</a>
  15. <a class="btn btn-primary" href="#">
  16. <i class="icon-refresh icon-spin"></i> Synchronizing Content...</a>

按钮组

   
  1. <div class="btn-group">
  2. <a class="btn" href="#"><i class="icon-align-left"></i></a>
  3. <a class="btn" href="#"><i class="icon-align-center"></i></a>
  4. <a class="btn" href="#"><i class="icon-align-right"></i></a>
  5. <a class="btn" href="#"><i class="icon-align-justify"></i></a>
  6. </div>

下拉菜单按钮

  1. <div class="btn-group open">
  2. <a class="btn btn-primary" href="#"><i class="icon-user"></i> User</a>
  3. <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="icon-caret-down"></span></a>
  4. <ul class="dropdown-menu">
  5. <li><a href="#"><i class="icon-pencil"></i> Edit</a></li>
  6. <li><a href="#"><i class="icon-trash"></i> Delete</a></li>
  7. <li><a href="#"><i class="icon-ban-circle"></i> Ban</a></li>
  8. <li class="divider"></li>
  9. <li><a href="#"><i class="i"></i> Make admin</a></li>
  10. </ul>
  11. </div>
 Don't forget to add the appropriate JavaScript to enable button dropdowns.

列表

  • Lists
  • Buttons
  • Button groups
  • Navigation
  • Prepended form inputs

Easily replace individual bullets.

  1. <ul class="icons">
  2. <li><i class="icon-ok"></i> Lists</li>
  3. <li><i class="icon-ok"></i> Buttons</li>
  4. <li><i class="icon-ok"></i> Button groups</li>
  5. <li><i class="icon-ok"></i> Navigation</li>
  6. <li><i class="icon-ok"></i> Prepended form inputs</li>
  7. </ul>

导航条

Use Font Awesome icons in navigation to provide helpful visual cues.

  1. <ul class="nav nav-list">
  2. <li class="active"><a href="#"><i class="icon-home"></i> Home</a></li>
  3. <li><a href="#"><i class="icon-book"></i> Library</a></li>
  4. <li><a href="#"><i class="icon-pencil"></i> Applications</a></li>
  5. <li><a href="#"><i class="icon-cogs"></i> Settings</a></li>
  6. </ul>

Prepended form inputs

 
 
  1. <form>
  2. <div class="input-prepend">
  3. <span class="add-on"><i class="icon-envelope"></i></span>
  4. <input class="span2" type="text" placeholder="Email address">
  5. </div>
  6. <div class="input-prepend">
  7. <span class="add-on"><i class="icon-key"></i></span>
  8. <input class="span2" type="password" placeholder="Password">
  9. </div>
  10. </form>

原文链接:http://www.bootcss.com/p/font-awesome/

Bootstrap + Font Awesome的更多相关文章

  1. Bootstrap & Font Awesome 学习笔记

    学习网站:http://bootstrap.ninghao.net/index.html https://www.freecodecamp.cn http://www.runoob.com/boots ...

  2. Bootstrap,Font Awesome等组件中 .woff字体报404错的解决办法

    参考资料:http://www.zhidao91.com/glyphicons-halflings-regular-woff-404-not-found/ http://shiyousan.com/p ...

  3. Bootstrap基础知识学习

    Bootstrap中文网 http://www.bootcss.com/ Bootstrap菜鸟教程 http://www.runoob.com/bootstrap/bootstrap-tutoria ...

  4. VueJS搭建简单后台管理系统框架(一)环境搭建

    做这份笔记的时候,Vue.js还是1.0,10月份Vue已经升级到2.0,这边也进行相应的更新,用Vue2.0进行一个简单的环境搭建 饿了么也刚好开源了其基于Vue.js的UI框架element-ui ...

  5. Python开发工程师技术手记

    Python基础篇 PythonPEP8规范 Python历史与安装 Python注释 Python变量以及类型 Python标识符和关键字 Python输出 Python输入 Python运算符 P ...

  6. 【前端积累】Awesome初识

    前言 之所以要看这个,是因为在看到的一个网站里图表显示的全屏和缩小,anyway ,还是看一下咯~ 一.介绍 Font Awesome 字体为您提供可缩放矢量图标,它可以被定制大小.颜色.阴影以及任何 ...

  7. http://www.bootcss.com/p/font-awesome/

    集成 将Font Awesome 集成到 Bootstrap 非常容易,还可以被单独使用. 最简单的 Bootstrap + Font Awesome 集成方式 使用这种方式将 Font Awesom ...

  8. vue-cli 该如何正确打包iconfont?

    其实这种问题应该问google的: got wrong bootstrap font path after building · Issue #166 · vuejs-templates/webpac ...

  9. Spring Boot + Bootstrap 出现"Failed to decode downloaded font"和"OTS parsing error: Failed to convert WOFF 2.0 font to SFNT"

    准确来讲,应该是maven项目使用Bootstrap时,出现 "Failed to decode downloaded font"和"OTS parsing error: ...

随机推荐

  1. LeetCode(21)Merge Two Sorted Lists

    题目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...

  2. STM32--TIM定时器时钟分割(疑难)

    不太明白 (1)        TIM_Perscaler来设置预分频系数: (2)        TIM_ClockDivision来设置时钟分割(时钟分频因子): (3)        TIM_C ...

  3. [第一波模拟\day1\T2]{分班}(divide.cpp)

    [题目描述] 小N,小A,小T又大了一岁了. 现在,他们已经是高二年级的学生了.众所周知,高二的小朋友是要进行文理科分班考试的,这样子的话,三个好朋友说不定就会不分在一个班. 于是三个人决定,都考平均 ...

  4. Leetcode 264.丑数II

    丑数II 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10 ...

  5. 使用jemalloc优化nginx和mysql内存管理

    预先安装autoconf 和 make yum -y install autoconf make jemalloc的安装jiemalloc 开源项目网站 http://www.canonware.co ...

  6. zju 3209 dancing links 求取最小行数

    题目可以将每一个格子都看做是一列,每一个矩形作为1行,将所有格子进行标号,在当前矩形中的格子对应行的标号为列,将这个点加入到十字链表中 最后用dlx求解精确覆盖即可,dance()过程中记得剪枝 #i ...

  7. [luoguP2577] [ZJOI2005]午餐(DP)

    传送门 显然吃饭时间越长的人排在前面越好,所以先排序. f[i][j]表示前i个人,A队的打饭时间为j的最优解,每个人只有两种选择,去A队或是去B队. #include <cstdio> ...

  8. Perforce share workspace between linux and windows

    p4 workspace 跨平台共享 (linux 和 window 共享) 用来存放代码的目录: linux存放代码目录: /home/username/ windows 上map network ...

  9. XCode warning:“View Controller” is unreachable because it has no entry points

    Unsupported Configuration: “View Controller” is unreachable because it has no entry points, and no i ...

  10. 洛谷—— P1133 教主的花园

    https://www.luogu.org/problem/show?pid=1133 题目描述 教主有着一个环形的花园,他想在花园周围均匀地种上n棵树,但是教主花园的土壤很特别,每个位置适合种的树都 ...