如何使用纸卡创建网格布局

时间:2016-04-23 23:08:10

标签: css polymer paper-elements

我正在尝试在Polymer Starter Kit中混合使用template repeaterthe paper-card tutorial

我的目标是复制那种网格: http://cdn.instantshift.com/wp-content/uploads/2014/11/material-design-01.jpg

我创建了两个自定义元素:

  1. 员工名单
  2. 员工
  3. 员工名单:

    <style is="custom-style">
    #board {
      @apply(--layout-vertical);           <<= HERE ARE DEFINED THE LAYOUT OF THE GRID
      @apply(--layout-wrap);
      height: 344px;
      width: 384px;
    }
    #board > paper-card {
      box-sizing: border-box;
      max-width: 184px;
      margin: 4px;
      flex: 0 0 auto;
    }
    </style>
      <template>
        <div id="board">
          <template is="dom-repeat" items="{{employeesArray}}">
              <employee-element name="{{item.title}}"
                               preview="{{item.preview}}"
                               width={{item.width}} height={{item.height}}>
              </employee-element>
          </template>
        </div>
      </template>
    

    员工:

    <paper-card
      heading="{{name}}"
      image="{{preview}}"
      style="max-width:{{width}}px;
             max-height:{{height}}px;"
      >
      <div class="card-actions">
        <paper-icon-button class="favorite" icon="favorite"></paper-icon-button>
        <paper-icon-button class="bookmark" icon="bookmark"></paper-icon-button>
        <paper-icon-button class="share" icon="social:share"></paper-icon-button>
      </div>
    </paper-card>
    

    这是我得到的:

    enter image description here

    如何处理预期的结果?是否有设置使卡自动排列?

    我怎样才能获得“回车”式的行为?

    回答结果(感谢@Snekw):

    步骤:

    在导入元素的位置添加以下行(在我的情况下为elements / elements.html)

    <link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html"> 
    

    我的员工列表元素现在看起来像:

    <style is="custom-style" include="iron-flex">
        .flex-wrap {
          @apply(--layout-horizontal);
          @apply(--layout-wrap);
        }
      </style>
      <template>
        <div class="container flex-wrap">
          <template is="dom-repeat" items="{{employeesArray}}">
              <employee-element name="{{item.title}}"
                               preview="{{item.preview}}"
                               width={{item.width}} height={{item.height}}>
              </employee-element>
    
          </template>
        </div>
      </template>
    

    我得到了这个结果:

    enter image description here

    我仍然需要解决纸卡操作面板的问题。

1 个答案:

答案 0 :(得分:2)

您需要在iron-flex代码中加入style课程。

<style is="custom-style" include="iron-flex">
//your styling
</style>

您需要加载iron-flex-layout-classes.html元素。 Iron-flex-layout元素包含--layout-vertical--layout-wrap属性。

更多关于iron-flex-layout的信息:iron-flex-layout-classes GitHub