如何在引导程序 3 中包含字形 [英] how to include glyphicons in bootstrap 3

查看:16
本文介绍了如何在引导程序 3 中包含字形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前没有使用过任何引导框架.我想在我的页面上的 bootstrap 3 中包含一些字形.据我所知,它们应该包含在我添加到我的页面的 bootstrap.css 文件中.当我查看 bootstrap.css 文件时,但我没有看到对它们的任何引用?虽然它是一个大文件,但我可能错过了一些东西.

我注意到当我打开从 bootstrap 3 下载的 dist 文件夹时,有一个单独的文件夹 fonts 包含名为:

glyphicons-halflings-regular.eotglyphicons-halflings-regular.svgglyphicons-halflings-regular.ttfglyphicons-halflings-regular.woff

这似乎是字形的位置,但我不知道如何将它们附加到我的网站?如何将字形附加到我的页面?

提前感谢您的帮助

下面的代码显示了附加的 bootstrap.css 文件:

<头><title>引导示例</title><meta name="viewport" content="width=divice-width, initial-scale=1.0"><!-- 引导程序--><link href="bootstrap.css" rel="stylesheet" media="screen">

这里是 html 代码的一部分,显示了字形应该在哪里:

 

解决方案

我认为您的具体问题不是如何使用 Glyphicons,而是了解 Bootstrap 文件如何协同工作.

Bootstrap 需要一个特定的文件结构才能工作.我从你的代码中看到你有这个:

您的 Bootstrap.css 正在从与您的页面相同的位置加载,如果您不调整文件结构,这会产生问题.

但首先,我建议您像这样设置文件夹结构:

/css <-- 这里是 Bootstrap.css/fonts <-- 这里是 Bootstrap 字体/img/js <-- 在此处引导 JavaScript索引.html

如果您注意到,这也是 Bootstrap 在其下载 ZIP 中构建文件的方式.

然后像这样包含 Bootstrap 文件:

或者<link href="./css/bootstrap.css" rel="stylesheet" media="screen">或者<link href="/css/bootstrap.css" rel="stylesheet" media="screen">

取决于您的服务器结构或您的目标.

第一个和第二个是相对于文件的当前目录的.第二个更明确,先说这里"(./),然后是 css 文件夹(/css).

如果您正在运行网络服务器,第三个是很好的,并且您可以使用相对于根符号,因为前导/"将始终从根文件夹开始.

那么,为什么要这样做?

Bootstrap.css 为 Glyphfonts 提供了以下特定行:

@font-face {font-family: 'Glyphicons Halflings';src: url('../fonts/glyphicons-halflings-regular.eot');src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') 格式('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') 格式('woff'), url('../fonts/glyphicons-halflings-regular.ttf') 格式('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular')格式('svg');}

您可以看到 Glyphfonts 是通过进入一个目录 ../ 然后查找名为 /fontsTHEN<的文件夹来加载的/em> 加载字体文件.

URL 地址相对于 CSS 文件的位置.因此,如果您的 CSS 文件位于这样的相同位置:

/fontsBootstrap.css索引.html

CSS 文件比查找 /fonts 文件夹更深一层.

那么,假设这些文件的实际位置是:

C:wwwfontsC:wwwBoostrap.cssC:wwwindex.html

从技术上讲,CSS 文件将在以下位置查找文件夹:

C:fonts

但您的文件夹实际上位于:

C:wwwfonts

所以看看这是否有帮助.您无需执行任何特殊"操作即可加载 Bootstrap Glyphicon,除非确保正确设置了文件夹结构.

当你解决这个问题时,你的 HTML 应该是:

<span class="glyphicon glyphicon-comment"></span>

注意,您需要两个类.第一类glyphicon 设置基本样式,而glyphicon-comment 设置特定图像.

I've not used any of the bootstrap frameworks before. I want to include some of the glyphicons in bootstrap 3 on my page. From what I understand they should be included in a bootstrap.css file which I've added to my page. When I've looked in the bootstrap.css file however I don't see any reference to them ? Although its a large file I may have missed something.

I have noticed that when I opened the dist folder downloaded from bootstrap 3 there is a separate folder fonts that contains files named:

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

It Seems like this is where the glyphicons are however I don't know how to attach these to my site? How do I attach the glyphicons to my page ?

Thanks for any help in advance

The code below shows the attached bootstrap.css file:

<!DOCTYPE html>
<html>
  <head>
    <title>Bootstrap example</title>
    <meta name="viewport" content="width=divice-width, initial-scale=1.0">
    <!-- Bootstrap -->
    <link href="bootstrap.css" rel="stylesheet" media="screen">
 </head>

and here is the part of the html code showing where the glyphicons should be:

      <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#"><span class="glyphicon glyphicon-home"></span>
           Home</a></li>    
          <li><a href="#"><span class="glyphicon glyphicon-star"></span> Top
           Destinations</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span    
            class="glyphicon glyphicon-user"></span> About Us<b class="caret"></b></a>

解决方案

I think your particular problem isn't how to use Glyphicons but understanding how Bootstrap files work together.

Bootstrap requires a specific file structure to work. I see from your code you have this:

<link href="bootstrap.css" rel="stylesheet" media="screen">

Your Bootstrap.css is being loaded from the same location as your page, this would create a problem if you didn't adjust your file structure.

But first, let me recommend you setup your folder structure like so:

/css      <-- Bootstrap.css here
/fonts    <-- Bootstrap fonts here
/img
/js       <-- Bootstrap JavaScript here
index.html

If you notice, this is also how Bootstrap structures its files in its download ZIP.

You then include your Bootstrap file like so:

<link href="css/bootstrap.css" rel="stylesheet" media="screen">
or
<link href="./css/bootstrap.css" rel="stylesheet" media="screen">
or
<link href="/css/bootstrap.css" rel="stylesheet" media="screen">

Depending on your server structure or what you're going for.

The first and second are relative to your file's current directory. The second one is just more explicit by saying "here" (./) first then css folder (/css).

The third is good if you're running a web server, and you can just use relative to root notation as the leading "/" will be always start at the root folder.

So, why do this?

Bootstrap.css has this specific line for Glyphfonts:

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

What you can see is that that Glyphfonts are loaded by going up one directory ../ and then looking for a folder called /fonts and THEN loading the font file.

The URL address is relative to the location of the CSS file. So, if your CSS file is at the same location like this:

/fonts
Bootstrap.css
index.html

The CSS file is going one level deeper than looking for a /fonts folder.

So, let's say the actual location of these files are:

C:wwwfonts
C:wwwBoostrap.css
C:wwwindex.html

The CSS file would technically be looking for a folder at:

C:fonts

but your folder is actually in:

C:wwwfonts

So see if that helps. You don't have to do anything 'special' to load Bootstrap Glyphicons, except make sure your folder structure is set up appropriately.

When you get that fixed, your HTML should simply be:

<span class="glyphicon glyphicon-comment"></span>

Note, you need both classes. The first class glyphicon sets up the basic styles while glyphicon-comment sets the specific image.

这篇关于如何在引导程序 3 中包含字形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆