【问题标题】:Polymer 1.x: Using Font Awesome with paper-icon-buttonPolymer 1.x:使用 Font Awesome 和 paper-icon-button
【发布时间】:2016-07-08 05:02:59
【问题描述】:

有没有办法使用图标from the Font Awesome library 作为paper-icon-button 中的图标?

Here is my jsBin.

http://jsbin.com/rahesepeho/2/edit?html,输出
<!doctype html>
<head>
  <meta name="description" content="iron-data-table beta3">
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-icon-button/paper-icon-button.html" rel="import"> 
</head>
<body>
  <dom-module id="x-foo">
    <style>
      :host {
        font-family: arial, sans-serif;
      }
    </style>
    <template>
      <p>The below <code>paper-icon-button</code> uses an image from Github.</p>
      <paper-icon-button
        src="https://assets-cdn.github.com/images/modules/logos_page/Octocat.png"
        alt="octocat" title="octocat">
      </paper-icon-button>
      <p>How do I make the below <code>paper-icon-button</code> use an icon from <a href="http://fontawesome.io/icons/" target="_blank">Font Awesome</a>?</p>
      <paper-icon-button
        src="https://assets-cdn.github.com/images/modules/logos_page/Octocat.png"
        alt="octocat" title="octocat">
      </paper-icon-button>
    </template>
    <script>
      document.addEventListener('WebComponentsReady', function() {
        Polymer({
          is: 'x-foo'
        });
      });
    </script>
  </dom-module>
  <x-foo></x-foo>
</body>

【问题讨论】:

  • Here 是相同的 bower 组件(尽管它缺少任何有关如何使用它的文档或示例)

标签: polymer font-awesome polymer-1.0 paper-elements fontawesome-4.4.0


【解决方案1】:

Polymer Slack 网站上的 @Stefanvott:

至少有两种方式:

  1. 使用以下自定义元素https://customelements.io/philya/font-awesome-polymer-icons/ (对我不起作用。)
  2. 这样做&lt;paper-icon-button src="" class="fa fa-github-alt fa-lg"&gt;&lt;/paper-icon-button&gt;per this jsBin。请参见下面的代码。
短版 http://jsbin.com/hubonatopa/1/edit?html,输出
paper-icon-button.fa {
    padding: .5em;
    height: 2em;
    width: 2em;
}
<paper-icon-button class="fa fa-github-alt fa-lg"></paper-icon-button>
完整版 http://jsbin.com/hubonatopa/1/edit?html,输出
<!doctype html>

<head>
  <meta name="description" content="iron-data-table beta3">
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-icon-button/paper-icon-button.html" rel="import">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css"> </head>

<body>
  <dom-module id="x-foo">
    <style>
      :host {
        font-family: arial, sans-serif;
      }

      paper-icon-button.fa {
        padding: 10px;
        line-height: 1em;
        overflow: hidden;
      }
    </style> <template>
      <p>The below <code>paper-icon-button</code> uses an image from Github.</p>
      <paper-icon-button src="https://assets-cdn.github.com/images/modules/logos_page/Octocat.png" alt="octocat" title="octocat"></paper-icon-button>
      <p>How do I make the below <code>paper-icon-button</code> use an icon from <a href="http://fontawesome.io/icons/" target="_blank">Font Awesome</a>?</p>
      <paper-icon-button class="fa fa-github-alt fa-lg"></paper-icon-button>
    </template>
    <script>
      document.addEventListener('WebComponentsReady', function() {
        Polymer({
          is: 'x-foo'
        });
      });
    </script>
  </dom-module>
  <x-foo></x-foo>
</body>

【讨论】:

    【解决方案2】:

    你可以使用这个项目!在聚合物 1-2 中使用很酷的凉亭包。现在是 FA 的最后一个版本:4.7。这里:https://github.com/vangware/fontawesome-iconset

    【讨论】:

      【解决方案3】:

      在我的情况下,在聚合物 v1.8 上,我必须创建一个自定义样式元素,如 link 中所述,将 font-awesome css 粘贴到那里,然后使用

         <template>
           <style include="shared-styles">
           </style>
           <paper-button> <i class="fa fa-facebook fa-lg"></i></paper-button>
         ..............
         </template>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-24
        • 1970-01-01
        • 2021-12-02
        • 1970-01-01
        • 2022-10-02
        • 2017-07-17
        相关资源
        最近更新 更多