1

有没有办法使用Font Awesome 库中的图标作为 a 中的图标paper-icon-button

这是我的 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>
4

3 回答 3

1

根据 Polymer Slack 网站上的@Stefanvott:

至少有两种方式:

  1. 使用以下自定义元素https://customelements.io/philya/font-awesome-polymer-icons/ (对我不起作用。)
  2. <paper-icon-button src="" class="fa fa-github-alt fa-lg"></paper-icon-button> 按照这个 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>
于 2016-07-08T07:29:35.867 回答
1

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

于 2018-01-24T16:51:50.953 回答
0

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

   <template>
     <style include="shared-styles">
     </style>
     <paper-button> <i class="fa fa-facebook fa-lg"></i></paper-button>
   ..............
   </template>
于 2017-03-11T22:34:00.720 回答