本章将讲解Bootstrap glyphicons字体图标,并通过一些实例了解它的使用,字体图标是在 Web 项目中使用的图标字体。字体图标在下载的Bootstrap的fonts文件夹中
 

本章将讲解字体图标(Glyphicons),并通过一些实例了解它的使用。Bootstrap 捆绑了 200 多种字体格式的字形。首先让我们先来理解一下什么是字体图标。

首先给大家介绍什么是字体图标:

字体图标是在 Web 项目中使用的图标字体。字体图标在下载的Bootstrap的fonts文件夹中。

1
2
3
4
5
6
7
8
9
10
11
.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 的相对位置,呈现为 inline-block,声明字体,规定 font-style 和 font-weight 为 normal,设置行高为 1。除此之外,使用-webkit-font-smoothing: antialiased 和 -moz-osx-font-smoothing: grayscale; 获得跨浏览器的一致性。

关于-webkit-font-smoothing和-moz-osx-font-smoothing:

-webkit-font-smoothing属性。这个属性可以使页面上的字体抗锯齿,使用后字体看起来会更清晰舒服。

none                               ------ 对低像素的文本比较好
subpixel-antialiased       ------默认值
antialiased                     ------抗锯齿很好
auto
inherit                           ------继承父元素
initial
-moz-osx-font-smoothing属性,其中-osx-表明这是mozilla难得的给特定操作系统推出的特性增强,由于缺乏文档,目前已知的取值是:

grayscale               ------抗锯齿很好
auto                   ------默认值
inherit                         ------继承

Bootstrap提供了200个字体图标,每个图标对应一个class,在使用时,我们只需要包含glyphicon和对应的class即可。

使用方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!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使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<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>

效果:

定制字体图标

在上一个例中,其实我们已经实现了对字体图标大小和颜色的定制,此处再做进一步说明。

通过改变字体的大小或button的大小,可以改变字体图标的大小。

通过设置color的颜色,可以改变字体图标的颜色,如下:

1
2
3
4
5
6
7
8
9
10
11
<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,都可以改变字体图标的颜色。

应用文本阴影

1
2
3
4
5
6
7
8
9
10
11
<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>

更多请查看字体图标,可以bootstrap官方文档:

以上内容给大家介绍了Bootstrap glyphicons字体图标的相关知识,希望大家喜欢。

BootStrap glyphicons字体图标的更多相关文章

  1. Bootstrap WPF Style(二)--Glyphicons 字体图标

    介绍 关于Glyphicons字体图标,首先给出友情链接 Glyphicons 这个项目是在Bootstrap WPF Style项目基础上做的,详见http://www.cnblogs.com/ts ...

  2. Glyphicons字体图标

    Glyphicons字体图标-----好处可以减少请求,容易控制样式! <p> <button type="button" class="btn btn ...

  3. Bootstrap--组件之Glyphicons字体图标

    Glyphicons 字体图标 所有可用的图标 包括250多个来自 Glyphicon Halflings 的字体图标.Glyphicons Halflings 一般是收费的,但是他们的作者允许 Bo ...

  4. 项目经验:Glyphicons字体图标改造,制造适合自己项目的字体图标

    Bootstrap对我们来说已经不陌生了,大型的项目一定会用到它.它的DOM结构,字体图标,组件,响应式布局等,很大程度上提高了WEB开发速度. 在bootstrap刚出来的时候,它拥有丰富的组件.美 ...

  5. Bootstrap进阶一:Glyphicons 字体图标

    基本组件是Bootstrap的精华之一,其中都是开发者平时需要用到的交互组件.例如:网站导航.标签页.工具条.面包屑.分页栏.提示标签.产品展示.提示信息块和进度条等.这些组件都配有jQuery插件, ...

  6. Bootstrap之字体图标

    优点:1.减少请求 2.容易控制样式 所在位置:在下载的bootstrap文件中的fonts文件夹存放字体图标 默认路径为当前目录下,如需修改路径,则需在bootstrap.css中查找font-fa ...

  7. 关于font awesome或Glyphicons字体图标不能正确显示的问题

    此处讨论的是关于本地字体的安装和引进 实际操作经验中,某些网站模板设置的CSS, FONTS目录较深,如果按默认的路径设置,字体图标死活都不会显示. 解决办法是将FONTS目录,安装在网站根目录下 C ...

  8. MVC.NET 发布后,部署到iis ,网站中的Bootstrap的字体图标不能正常显示

    时隔多日没有在博客中记录自己遇到的问题及解决方案了 ,今天给大家分享一个可能会遇到的一个鸡肋bug ! 如果你的项目是MVC并且在项目中引用了 Boostrap 框架,你在编辑发布后部署到iis的时候 ...

  9. Glyphicons 字体图标

随机推荐

  1. ASP获取json天气信息

    ASP代码(ASP获取页面源码方法,有编码.超时时间参数,处理了乱码.超时的问题): Function GetHttpPage(HttpUrl) Then GetHttpPage="$Fal ...

  2. Oracle-11g 从表空间删除数据文件

    从表空间删除数据文件前提条件 如果欲从表空间中删除数据文件,那么该数据文件必须为空,否则将报出"ORA-03262: the file is non-empty"的错误.   从表 ...

  3. CSMA/CD协议——学习笔记

    CSMA/CD协议要点: 1)适配器从网络层获得一个分组,加上以太网的首部和尾部,组成以太网帧,放入适配器的缓存中,准备发送. 2)若适配器检测到信道空闲(即在96比特时间内没有检测到信道上有信号), ...

  4. ie6的兼容问题及解决方案

    1.png24位的图片在ie6浏览器上会出现背景,解决方案是做成png8位: 2.浏览器默认的margin和padding不同,解决方法是用全局重置来统一,即是*{margin:0;padding:0 ...

  5. PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解

    #include <string> #include <iostream> #include <cstring> #include <algorithm> ...

  6. 关于Struts2的客户端校验的FreeMarker template error!

    把<s:form action="login" namespace="/" validate="true" >改为 <s: ...

  7. 一个简单的小例子让你明白c#中的委托-终于懂了!

    模拟主持人发布一个问题,由多个嘉宾来回答这个问题. 分析:从需求中抽出Host (主持人) 类和Guests (嘉宾) 类. 作为问题的发布者,Host不知道问题如何解答.因此它只能发布这个事件,将事 ...

  8. 4K Block Size的Device和 Aligned IO

    http://www.cnblogs.com/cenalulu/p/3587006.html   背景:最近采购了一批新的服务器,底层的存储设备的默认physical sector size从原有的 ...

  9. Jetty学习(一)

           最近做一个项目,需要动态添加与移除servlet容器的http端口,并且启动都是嵌入式的.因此,果断选择了Jetty.        在模块化方面,Jetty是做的相当给力的一个容器,对 ...

  10. divide-conquer-combine(4.1 from the introduction to algorithm)

    this example is from chapter 4 in <the introduction to algorithm> the main idea is all showed ...