1

我正在努力iron-listiron-flex-layoutand相处融洽paper-card。我希望的是paper-card在两个轴上弯曲扩展以覆盖页面(其边距作为保险杠),然后iron-list在其容器中垂直扩展以显示我的铁列表及其所有“虚拟列表”魔法.

我哪里错了?

<script src="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/webcomponentsjs/webcomponents-lite.min.js"></script>

<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/paper-card/paper-card.html">
<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/paper-progress/paper-progress.html">
<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="https://cdn.rawgit.com/Download/polymer-cdn/24b44b55/lib/iron-list/iron-list.html">

<style is="custom-style" include="iron-flex iron-flex-alignment iron-positioning">
  body {
    margin: 0;
    height: 100vh;
  }

  paper-card {
    margin: 1em;
  }

  iron-list {
    border-bottom: 1px solid #f00;
    border-top: 1px solid #000;
  }
</style>

<div class="vertical layout">
  <template is="dom-bind" id="app">
    <paper-card heading="My paper card" class="flex">
      <div class="card-content layout vertical">
        <div>[[listing.length]]</div>
          <iron-list items="[[listing]]" class="flex">
            <template>
              <div class="layout horizontal">
                <div>[[item.name]]</div>
                <div>[[item.value]]</div>
              </div>
            </template>a
          </iron-list>
      </div>
    </paper-card>
  </template>
</div>

<script>
  "use strict";

  window.addEventListener('WebComponentsReady', e => {
    app.listing = [];
    for (var i = 0; i < 100; i++) {
      app.push('listing', { name: i, value: i });
    }
  });
</script>

小提琴:https ://jsfiddle.net/4czLkjfj/

4

1 回答 1

1

您已将body元素设置为height: 100vh.

然而,这个高度并没有被向下一层的 flex 容器继承。

一种解决方案是添加display: flexbody. 这将创建一个自动应用于align-items: stretch子级的 flex 容器。

body {
  display: flex;
  align-items: stretch; /* initial setting; can be omitted */
}

div.vertical.layout {
  flex: 1; /* full width */
}

修改后的小提琴

另一种解决方案是简单地告诉 flex 容器继承父级的高度。

div.vertical.layout {
  height: 100%;
}

修改后的小提琴


根据评论中的反馈修改解决方案:演示

于 2017-03-20T23:30:26.840 回答