简体   繁体   English

Bootstrap 3 Glyphicons无法正确显示

[英]Bootstrap 3 Glyphicons not showing correctly

I haven't had much issue picking up bootstrap so far, however tonight I tried integrating glyphicons inside a navbar element and have been unable to get it to work. 到目前为止,我没有太多的问题来获取引导程序,但是今晚我尝试将glyphicons集成到navbar元素中,但无法使其正常工作。 The image shows the character that appears in the glyphicons place; 该图显示了出现在字形图标位置的字符; code below it. 下面的代码。

格式错误的字形图标

<link href="/userpath/code/js/bootstrap-3.3.1/dist/css/bootstrap.min.css" rel="stylesheet">

<!-- Bootstrap theme -->
<link href="/userpath/code/js/bootstrap-3.3.1/dist/css/bootstrap-theme.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="style.css" rel="stylesheet">
 <nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">name</a>
    </div>
    <ul class="nav navbar-nav">
      <li><a href="#">  About Me</a></li>
      <li><a class="navbar-link" href="#"><span class="glyphicon glyphicon-star" aria-hidden="true"></span>  Projects</a></li>
      <li><a href="#">  Past</a></li>
      <li><a href="#">  Free Time</a></li>
    </ul>
  </div>
</nav>

I first consorted the BS3 documentation like any reasonable person and found this. 我首先像任何理智的人一样整理BS3文档,然后发现了这一点。

Only for use on empty elements: Icon classes should only be used on elements that contain no text content and have no child elements. 仅用于空元素:图标类仅应用于不包含文本内容且不包含子元素的元素。

Not feeling 100% satisfied with that, I found a number of examples showing icons within button objects. 我对此并不感到100%满意,我发现了许多示例,这些示例在按钮对象中显示了图标。 One demo is here . 一个演示在这里 This led me to believe that my problem went beyond compatibility with BS3. 这使我相信我的问题超出了与BS3的兼容性。 I continued looking and found this helpful post saying to redownload the source code for the font files. 我继续寻找,发现这篇有用的文章说要重新下载字体文件的源代码。 The problem was still there after trying this. 尝试此操作后问题仍然存在。 I've also double checked that my bootstrap.min.css is formatted correctly. 我还仔细检查了bootstrap.min.css的格式是否正确。 For those who might still think that this is a navbar issue, I tried implementing a button seen in the demo but have the same issue with that. 对于那些仍然可能认为这是导航栏问题的人,我尝试实现了演示中看到的按钮,但仍然存在相同的问题。

Do I need to explicitly format the glyphicons in the .css? 我是否需要在.css中显式格式化字形? From what I've read, I have everything I need for this to work correctly. 从我所读的内容中,我已经具备了正常工作所需的一切。 Please let me know what I'm doing wrong. 请让我知道我在做什么错。

For those who care, I'm using Mozilla 34.0.5 on a Mac Book Pro OSX 10.9.5 (not that OS should matter). 对于那些在乎的人,我在Mac Book Pro OSX 10.9.5上使用Mozilla 34.0.5(不是操作系统应该很重要)。

UPDATE 更新

I attempted Shikar's suggestions but couldn't get them to work. 我尝试了Shikar的建议,但无法使它们起作用。 When I looked in my bootstrap.min.css, I saw src:url(../fonts/glyphicons...) . 当我查看bootstrap.min.css时,看到了src:url(../fonts/glyphicons...) I made two attempts to change these urls. 我做了两次尝试来更改这些URL。 The first I simply deleted the .. before /fonts/ . 首先,我只是删除了/fonts/之前的.. This changed nothing. 这没有改变。 I then realized that I've put my bootstrap in a separate directory so I called the files explicitly by putting `/Users/myname/explicitPath/bootstrap-3.3.1/dist/fonts/glyphicons-halflings-regular.eot) along with the other four glyphicon urls mentioned in this area of the .css. 然后我意识到我已经将引导程序放在了一个单独的目录中,因此我通过将`/Users/myname/explicitPath/bootstrap-3.3.1/dist/fonts/glyphicons-halflings-regular.eot)与.css区域中提到的其他四个glyphicon网址。 This also didn't work. 这也没有用。 Taking @rockerest 's advice, I looked in the FF's webdev tool and see two failed downloads with the downloadable font. 在@rockerest的建议下,我查看了FF的webdev工具,并看到两次下载字体可下载的失败。 The filepath for for these errors don't have any mistaks but am I misunderstanding how to use bootstrap locally? 这些错误的文件路径没有任何错误,但是我是否误解了如何在本地使用引导程序? Can I not use local filepaths in the bootstrap.min.css? 我不能在bootstrap.min.css中使用本地文件路径吗?

So my problem ended up being where bootstrap was in relation to my index.html. 因此,我的问题最终出现在与我的index.html相关的引导程序所在的位置。 Below is the file structure before and after. 以下是之前和之后的文件结构。 I was hoping to just have a general bootstrap folder that I could point to file developing multiple web app ideas, but it looks like boot strap is required to be at the same level as your index.html. 我希望只有一个通用的Bootstrap文件夹,可以指向开发多个Web应用程序构想的文件,但是看起来引导带必须与index.html处于同一级别。 By moving bootstrap into the same directory as the index.html, executing grunt dist in the bootstrap directory and using the explicit path of the bootstrap.min.css in .html references, I was able to get things to work properly. 通过将引导程序移到与index.html相同的目录中,在引导程序目录中执行grunt dist并使用.html引用中的bootstrap.min.css的显式路径,我可以使事情正常进行。 Wish I had a better understanding as to why this worked though. 希望我对此有一个更好的理解。

Before                    After
├── webpage/              └── webpage/
|   └──index.html             ├──index.html
|                             └──bootstrap/
└── js/
    └──bootstrap/

had a similar problem, solved it putting the fonts directory in the same directory where the css folder is located. 有一个类似的问题,解决了将fonts目录放在css文件夹所在的目录中的问题。 For example if css folder is placed in the root directory place the fonts folder in the root. 例如,如果将css文件夹放置在根目录中,则将fonts文件夹放置在根目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM