【问题标题】:bootstrap Glyphicons引导 Glyphicons
【发布时间】:2012-03-18 04:34:27
【问题描述】:

Bootstrap css 使用来自Glyphicons 的半身人。 如果我购买了他们的完整产品线,我将如何将其整合到引导框架中?

【问题讨论】:

  • 我问了艺术家,他说“很高兴你对 Glyphicons 感兴趣!关于你的问题:目前,Twitter 的 Bootstrap 中没有 ALL Glyphicons 之类的东西,但它很好想法,我会考虑的。”
  • 嗨@phillip 你有没有为此修改过.less 文件?介意分享一下吗?
  • 不,我只是继续前进。我只是想知道,但这不是必需的。

标签: css twitter-bootstrap


【解决方案1】:

使用此CSS sprite generator,上传 zip 文件。它将为您创建相关的 CSS 类(名称取自图像本身),将所有图像合并到一个(透明)PNG 中。

【讨论】:

  • 优秀的建议Gremo,这个工具会帮你搞定的。
  • 格雷莫,你太棒了。使用您的建议,我能够为我的网站创建一个无字形图标的设置。现在我有 420 个图标可供使用。我对其他人的步骤:我从文件名中删除了 'glyphicons-###_' 并将图像缩小 56% 以使其与现有的引导 glyphicons 设置相匹配。
  • gremo--我刚找到这个话题,不得不感谢你。那个精灵生成器非常棒。真的很棒。非常非常感谢!
【解决方案2】:

您也可以使用Font Awesome 解决方案。

可缩放矢量图形意味着图标在任何尺寸下看起来都很棒。

从头开始设计,完全向后兼容 Twitter Bootstrap 2.0。

【讨论】:

  • 实际上我发现它在小尺寸下的渲染效果很差。
  • 图标的宽度也不同,所以在布局上它们是无用的。
  • 这是正确的方向!和许多其他人一样,我认为我会用它搞砸一切。好吧,像我一样阅读主页,它与引导程序集成得很好。非常感谢。
  • 你不知何故错过了这个问题。虽然 Font Awesome 真的很棒,但 OP 购买了 Glyphicons 并想使用它们。所以建议其他图标字体对他没有帮助。
【解决方案3】:

您必须将每个字形图标的背景位置重新计算到您自己的类中,或者覆盖引导程序已经设置的类才能使用它们。Twitter 的引导程序使用 14 像素的半身人(免费)版本的图标到处都是,全套尺寸是原来的两倍,所以旧的background-position's 将无法使用。

以下是引导图标类之一的示例:

/* class for the icon "fast-backward", notice the positioning values set in pixels */
.icon-fast-backward {
    background-position: -216px -72px;
}

/* main class, defining what icon sheet to use */
[class^="icon-"], [class*=" icon-"] {
    background-image: url("../img/glyphicons-halflings.png");
    background-position: 14px 14px;
    background-repeat: no-repeat;
    display: inline-block;
    height: 14px;
    line-height: 14px;
    vertical-align: text-top;
    width: 14px;
} 

【讨论】:

    【解决方案4】:

    我也在 Github 上创建了一个。之后才看到上面 Marco 的帖子。

    https://github.com/ekryski/bootstrap-template

    【讨论】:

    • 非常感谢 ekryski!我最近了解了 unicode,我想知道为什么像 bootstrap 这样的框架没有使用它,除非他们觉得他们的 sprite 在浏览器中是一致的。
    • 哦,我看到了 Marco 对我上面评论的评论。
    【解决方案5】:

    据我回忆,Glyphicons 并没有将他们的图标作为精灵版本提供(许多图标作为一个图像),而是您单独获取每个图标。如果你只打算使用他们的几个图标,这应该没问题。

    最好的方法是创建一个单独的 css 文件并继续使用它们的“.icon-”命名约定。

    .icon-whatever {
       background:url('..img/someicon.png') 0 0; 
    }
    

    默认背景位置为14px 14px,因此您需要将其重置为0 0,就像我在上面所做的那样。

    【讨论】:

    • Bootstrap 版本绝对是精灵。
    • Bootstrap 可能是,但 Makotosan 是正确的,Glyphicons pro 未随 sprite 图像分发。这是 Glyphicons Pro zip 文件提供的 png 的生成器/css。 gist.github.com/2694578
    【解决方案6】:

    我为 Bootstrap 创建了一个 sprite 和 CSS 插件来提供此功能。回购和说明在Github。并非每个图标都有覆盖范围,有些图标仍然略微偏离中心。要使用更大的图标,只需添加 icon-large CSS 类:

    <i class="icon-large icon-search"></i>
    

    【讨论】:

    • 谢谢马可!我也注意到unicode中有很多图标。我想知道为什么引导程序不使用它?我想这是因为它们可能因一种浏览器而异。
    【解决方案7】:

    这里有一篇关于引导图标的精彩文章:http://www.themplio.com/twitter-bootstrap-icons

    【讨论】:

    • 好的,太好了。嘿,你见过unicode吗?我不敢相信现在浏览器内置了这么多,比如:✔
    • @Phillip,现在在这里 - ✔ :)
    【解决方案8】:

    不需要合并它。您只需添加字形图标并将其与附带的半身人引导程序一起使用。

    如下添加字形图标(正则集):

    /css/glyphicons.css 
    /fonts/glyphicons-regular.eot 
    /fonts/glyphicons-regular.svg 
    /fonts/glyphicons-regular.ttf 
    /fonts/glyphicons-regular.woff 
    /fonts/glyphicons-regular.woff2
    

    您可能应该给 base-css-class: .glyphicons 与引导程序 .glyphicon 相同的样式

    .glyphicons {
        position:relative;
        top:2px; 
        display:inline-block;
        font-family:'Glyphicons Regular';
        font-style:normal;
        font-weight:normal;
        line-height:1;
        vertical-align:top;
        -webkit-font-smoothing:antialiased;
        -moz-osx-font-smoothing:grayscale
    }
    

    接下来,将字形图标的引用添加到您的页面中,如下所示:

    <link href="/css/glyphicons.css" rel="stylesheet" />
    

    现在,将完整的“常规”字形与半身人一起使用:

    <!-- halflings / bootstrap 3 -->
    <span class="glyphicon glyphicon-glass"></span>
    
    <!-- Glyphicons Regular set (note the plural suffix!) -->
    <span class="glyphicons glyphicons-glass"></span>
    

    其他答案很好,但请记住使用字体技术的图标和使用 sprite-png 的旧技术之间的区别。 Png 并不总是可缩放的,因此有多种尺寸。此外,无法设置颜色。为了与背景形成对比,.white 类可用于 png 以从黑色切换到白色。通过使用字体,为图标设置样式,就像设置字体样式一样:

    .iconstyle {  color: blue;  font-size: 26px;  etc.. }
    

    【讨论】:

      【解决方案9】:

      你可以使用我的解决方案。将此行放在标题上的引导链接 url css 之后。

      <link href="../assets/css/bootstrap.css" rel="stylesheet">
      <link href="../assets/css/opa-icons.css" rel="stylesheet">
      

      然后调用在线html代码

      <i class="icon-close icon-red"></i>&nbsp;Someting <!-- 16x16pix size color red -->
      <i class="icon32 icon-close icon-blue"></i>&nbsp;Someting <!-- 32x32pix size color red -->
      

      你可以在这里下载资源(图片-图标 png 和 css 都在 zip 中):

      http://www.photonautes-associes.fr/utils/assets.zip 享受:)

      【讨论】:

      • 谢谢布鲁诺!我去看看!
      【解决方案10】:

      从官方引导页面下载字体,然后将此代码按原样粘贴到您的 CSS 文件中

      试试这个代码

      @font-face{
      font-family: 'Glyphicons Halflings';
      src: url('/fonts/glyphicons-halflings-regular.eot');}
      

      【讨论】:

        【解决方案11】:

        我想我会把我的经验添加到这里的列表中。

        在尝试将 Glyphicons All 添加到我现有的、迷宫般的、充满 Bootstrap 的代码库时,我遇到了一些障碍。 (其中,Glyphicons All 使用结构“.glyphicons .glyphicons-[name]”,Bootstrap 使用结构“.glyphicon .glyphicon-[name]”)。

        我最终决定同时使用它们。展望未来,我发现我越来越多地使用 Glyphicons All 构造,但 Bootstrap 构造仍然适用于我现有的所有代码。

        是的,包括这两种“字体”都会增加整个页面的重量,但不会造成灾难性的后果。

        【讨论】:

        • 谢谢@skybondsor。几年前我问过这个问题。也许我应该重新审视它,但我不知道。我只是满足于免费的东西,而不是花 59 美元来添加不同的图标。
        • 多年来我一直对免费版本感到满意!但最近我需要推特“回复”的后退箭头图标,并认为可能是我踢那个家伙一些钱的时候了。
        【解决方案12】:

        我所做的非常简单,而且效果很好。注意:如果您希望将那些漂亮的字形图标用作字体,就像我正在使用的引导版本一样。

        1. 在 glyphicons zip 中,将 /glyphicons/web/bootstrap_example/fonts 中的所有字体复制到您的引导字体当前在项目中的位置

        2. 在 glyphicons zip 中,查看 /web/bootstrap_example/css/glyphicons.css,将所有内容复制并粘贴到您自己的 less/css 文件中。

        3. 1234563 (即 .glyphicon-xxxx:before { content: ... })。
        4. 在包含所有新标签的 less/css 文件中,进行查找和替换 “.glyphicons-”替换为“.glyphicon-”

        应该就是这样,除非我忘记了一些简单的事情。对我很有用。

        【讨论】:

          【解决方案13】:

          使用glyphicons classess,例如:

          `<span class="glyphicon glyphicon-search" aria-hidden="true"></span>`
          

          我最喜欢的图标字体是Fontello,你可以下载你需要的图标而不是整个包。

          【讨论】:

            猜你喜欢
            • 2015-05-11
            • 1970-01-01
            • 1970-01-01
            • 2014-05-27
            • 2015-07-08
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-11-27
            相关资源
            最近更新 更多