首页 > 解决方案 > Ionic 4 离子排填充剩余高度

问题描述

如何注释 anion-row以使其填充剩余空间?

对于以下示例,黄色行“内容”应展开,直到占用所有剩余(绿色)空间。

<ion-grid style="background-color: green; height: 100%;">
  <ion-row>
    <ion-col text-center style="background-color: purple;">
      <p>Example text</p>
    </ion-col>
  </ion-row>

  <ion-row>
    <ion-col text-center style="background-color: yellow">
      <p>Content</p>
    </ion-col>
  </ion-row>

  <ion-row>
    <ion-col text-center style="background-color: blue;">
      <p>Example text</p>
    </ion-col>
  </ion-row>
</ion-grid>

彩色行示例

类似的问题被问到 Bootstrap 并通过 flex-grow 得到解决。请参阅:Bootstrap 4 行填充剩余高度

但是我们可以在坚持行/列语法的同时拉伸行而不引入更多的弹性框吗?

标签: ionic-frameworkionic4

解决方案


可以用 注释网格容器,用 注释display: flex; flex-flow: column拉伸行flex-grow: 1

<ion-grid style="background-color: green; height: 100%; display: flex; flex-flow: column;">
  <ion-row>
    <ion-col text-center style="background-color: purple;">
      <p>Example text</p>
    </ion-col>
  </ion-row>

  <ion-row style="flex-grow: 1;">
    <ion-col text-center style="background-color: yellow">
      <p>Content</p>
    </ion-col>
  </ion-row>

  <ion-row>
    <ion-col text-center style="background-color: blue;">
      <p>Example text</p>
    </ion-col>
  </ion-row>
</ion-grid>

然后它看起来像这样: 解决方案

当网格压缩(而不是拉伸)时,行在彼此内部移动。为了防止flex-shrink: 0;在每一行上使用这种方法。


推荐阅读