栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > Bootstrap教程

Bootstrap 字形图标(Glyphicons) · Bootstrap教程

Bootstrap 字形图标(Glyphicons)

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

什么是字形图标(Glyphicons)?

字形图标(Glyphicons)是在 Web 项目中使用的图标字体。虽然,Glyphicons Halflings 需要商业许可,但是您可以通过基于项目的 Bootstrap 来免费使用这些图标。

为了表示对图标作者的感谢,希望您在使用时加上 GLYPHICONS 网站的链接。

获取字形图标(Glyphicons)

我们已经在 环境安装 章节下载了 Bootstrap 3.x 版本,并理解了它的目录结构。在 fonts 文件夹内可以找到字形图标(Glyphicons),它包含了下列这些文件:

    glyphicons-halflings-regular.eot
    glyphicons-halflings-regular.svg
    glyphicons-halflings-regular.ttf
    glyphicons-halflings-regular.woff

相关的 CSS 规则写在 dist 文件夹内的 css 文件夹内的 bootstrap.cssbootstrap-min.css 文件上。

字形图标(Glyphicons)列表

点击这里,查看可用的字形图标(Glyphicons)列表。

CSS 规则解释

下面的 CSS 规则构成 glyphicon class。

@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');
}

.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;
}

所以 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; 获得跨浏览器的一致性。

然后,这里的

.glyphicon:empty {
  width: 1em;
}

是空的 glyphicon。

这里有 200 个 class,每个 class 针对一个图标。这些 class 的常见格式如下:

.glyphicon-keyword:before {
  content: "hexvalue";
}

比如,使用的 user 图标,它的 class 如下:

.glyphicon-user:before {
  content: "e008";
}

用法

如需使用图标,只需要简单地使用下面的代码即可。请在图标和文本之间保留适当的空间。

下面的实例演示了如何使用字形图标(Glyphicons):




   Bootstrap 实例 - 如何使用字形图标(Glyphicons)
   
   
   



结果如下所示:


如何使用字形图标(Glyphicons)

带有导航栏的字形图标(Glyphicons)



  
    导航栏的字形图标
    
    
    
    
    body {
    padding-top: 50px;
    padding-left: 50px;
    }
    
    
  
  
    
      
        
          
          Project name
        
        
          
    Home
    Shop
    Support

定制字形图标(Glyphicons)

我们已经看到如何使用字形图标(Glyphicons),接下来我们看看如何定制字形图标(Glyphicons)。

我们将以上面的实例开始,并通过改变字体尺寸、颜色和应用文本阴影来进行定制图标。

下面是开始的代码:


效果如下所示:



定制字体尺寸

通过增加或减少图标的字体尺寸,您可以让图标看起来更大或更小。




定制字体颜色




应用文本阴影




在线定制字形图标(Glyphicons)

点击这里,在线定制字形图标(Glyphicons)。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/10662.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号