【问题标题】:Bootstrap 3 glyphicons not displaying correctlyBootstrap 3 字形图标无法正确显示
【发布时间】:2015-03-23 23:04:34
【问题描述】:

我在网站上使用 Bootstrap 3 的字形图标。它在浏览器中运行良好,但在某些设备上却不能,因为它显示为问号。

我找到了这个修复:Some of Bootstrap3 glyphicons are not displayed correctly on phonegap android webview,它修复了设备上的问题,但现在 glyphicon 在 Firefox 中不起作用。 (我正在覆盖 Bootstrap 默认值以在我的 CSS 中使用实际的、非转义字形。)我想知道是否有一种方法可以使用 Firefox 的浏览器检测来编写一些 jquery 以删除我的 CSS 文件中的覆盖并恢复它回到 Bootstrap 的 CSS。

我找到了这个用于浏览器检测的 jQuery 插件:https://github.com/gabceb/jquery-browser-plugin

代码:
JS

if ( $.browser.mozilla ) {
    $('a#calendar span').removeClass('glyphicon-calendar');
    $('a#calendar span').css({'glyphicon-calendar:before': 'content: "\1f4c5"'});
    }

CSS 覆盖 Bootstrap

/* fix glyph not showing on some devices--override the Bootstrap defaults to use the actual, non-escaped glyphs */ 
.glyphicon-calendar:before { 
  content: "\d83d\dcc5";
  }

Bootstrap 的 CSS

.glyphicon-calendar:before {
content: "\1f4c5";
}

感谢您的帮助。

【问题讨论】:

标签: twitter-bootstrap twitter-bootstrap-3 glyphicons


【解决方案1】:

您可以使用.glyphicon-nonescaped 类,让您在默认转义字形和非转义字形之间切换:

HTML

<i class="glyphicon glyphicon-calendar glyphicon-nonescaped"></i>

CSS

.glyphicon-nonescaped.glyphicon-calendar:before { 
    content: "\d83d\dcc5";
}

jQuery

​​>
if($.browser.mozilla) {
    $('.glyphicon-nonescaped').removeClass('glyphicon-nonescaped');
}

【讨论】:

    【解决方案2】:

    上述解决方案适用于各种操作系统。您可以将此代码添加到您的 css 文件中,它可能适用于无设备代码:

    .glyphicon-bell:before {
      content: "\d83d\dd14";
    }
    .glyphicon-bookmark:before {
      content: "\d83d\dd16";
    }
    .glyphicon-briefcase:before {
      content: "\d83d\dcbc";
    }
    .glyphicon-calendar:before {
      content: "\d83d\dcc5";
    }
    .glyphicon-camera:before {
      content: "\d83d\dcf7";
    }
    .glyphicon-fire:before {
      content: "\d83d\dd25";
    }
    .glyphicon-lock:before {
      content: "\d83d\dd12";
    }
    .glyphicon-paperclip:before {
      content: "\d83d\dcce";
    }
    .glyphicon-pushpin:before {
      content: "\d83d\dccc";
    }
    .glyphicon-wrench:before {
      content: "\d83d\dd27";
    }
    

    【讨论】:

      【解决方案3】:

      为避免使用 Javascript,您可以在 CSS 中使用媒体查询:

      对于 Firefox:

      @-moz-document url-prefix() { 
               .glyphicon-nonescaped.glyphicon-calendar:before {
                   content: "\d83d\dcc5";
               }
          }
      

      对于 IE 8+:

      @media screen\0 { 
             .glyphicon-nonescaped.glyphicon-calendar:before {
                 content: "\d83d\dcc5";
             }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-15
        • 2016-11-06
        • 2013-09-07
        • 2016-05-08
        • 2014-08-27
        • 2016-01-14
        • 1970-01-01
        • 2019-12-28
        相关资源
        最近更新 更多