【问题标题】:Glyphicon showing as box with hex code insideGlyphicon 显示为带有十六进制代码的框
【发布时间】:2016-11-28 20:44:19
【问题描述】:

我在使用折叠按钮时遇到问题。我正在尝试在按钮上显示一个字形图标,并在我单击它时使其更改。折叠时的向右箭头和向下箭头。在其他页面上,字形图标起作用。这个虽然在导航栏上。它显示为一个盒子,里面有十六进制代码。我已经看了几个小时的问题,他们几乎错过了字体系列。我有一部分正在工作,所以它有所不同,我找不到问题。

<button type="button" aria-expanded="false" class="btn navbar-toggle collapsed" data-toggle="collapse" data-target="#navigation">
    <span class="sr-only">Ouvrir la navigation</span>
</button>

这是字形图标工作的 css 部分:

.liens:before {
    content: "\e144";
    font-family: 'Glyphicons Halflings';
    font-size: 12px;
    float: left;
    margin-top: 0;
    margin-left: -20px;
    color: #2A3E53;
}

我可以在 ul 中的每个项目上看到字形图标,但在导航上我有完全相同的 css,但它显示为一个带有十六进制代码的框,即:e250

button.btn.collapsed:before {
    content: "\e250";
    font-family: 'Glyphicons Halflings' !important;
    font-size: 12px;
    float: left;
    color: #2A3E53;
}
button.btn:before {
    content: "\e252";
    font-family: 'Glyphicons Halflings' !important;
    font-size: 12px;
    float: left;
    color: #2A3E53;
}

这就是我得到的:

【问题讨论】:

  • 你确定 'Glyphicons Halflings' 有这个 Unicode 定义吗?
  • 它在website here 上。那么必须是“在这里获取专业版”。感谢您指出这一点。

标签: html css twitter-bootstrap glyphicons


【解决方案1】:

您可以探索bootstrap.css 文件如何定义Glyphicons Halflings font-family:

@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.woff2') format('woff2'), 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');
}

所以我猜你需要检查glyphicons-halflings-regular.* 文件的路径。

我使用 Bootstrap 的 default navbar 作为示例,删除了 .btn 类并简化了您的 CSS。请检查结果。是你想要达到的吗?

.navbar-toggle:after {
  content: "\e252"; /* glyphicon-triangle-bottom */
  font-family: 'Glyphicons Halflings';
}
.navbar-toggle.collapsed:after {
  content: "\e250"; /* glyphicon-triangle-right */
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">

<nav class="navbar navbar-default">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-example" aria-expanded="false">
        <span class="sr-only">Ouvrir la navigation</span>
      </button>
      <a class="navbar-brand" href="#">Brand</a>
    </div>

    <div class="collapse navbar-collapse" id="navbar-example">
      <ul class="nav navbar-nav">
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
      </ul>
    </div>
  </div>
</nav>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

【讨论】:

  • 是的,除了字形图标不显示外,一切正常。在 Visual Basic 中创建新项目时,bootsrap 附带了 3.0 版,我刚刚更新到 3.3.7,它运行良好!当我看到您指向 3.3.6 的链接时,就是这样。
  • @SteveMorin 哦,这很有趣。 Bootstrap 3.0 包含 Glyphicons Halflings 没有 \e250\e252
  • @GlebKemarsky BS 3.3.6 有(不知道如何换行):.glyphicon-triangle-right:before { content: "\e250"; } .glyphicon-triangle-left:before { content: "\e251"; }
  • @JasonRice 是的,我从这些行中获取了content 属性的值。我复制了.glyphicon-triangle-bottom:beforeglyphicon-triangle-right:before的代码,因为问题的作者在他的代码中使用了\e252\e250的值。
  • @JasonRice 是的,我在 cmets 中向 SteveMorin 写了关于 BS 3.0.0 的文章,并添加了指向 maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.css 的链接。此文件没有 \e250 和`\e252`,这是新闻对我来说也是。
猜你喜欢
  • 2011-05-17
  • 2019-01-01
  • 1970-01-01
  • 2012-02-14
  • 1970-01-01
  • 2015-10-26
  • 1970-01-01
  • 2014-01-15
  • 2019-04-24
相关资源
最近更新 更多