【问题标题】:Ionic 4 ion-row fill remaining heightIonic 4 离子排填充剩余高度
【发布时间】:2018-12-05 18:12:28
【问题描述】:

如何注释ion-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 row fill remaining height

但是我们可以在坚持 th row/col 语法的同时拉伸行而不引入更多的 flexbox 吗?

【问题讨论】:

    标签: ionic-framework ionic4


    【解决方案1】:

    可以用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;

    【讨论】:

    • 如果它们是更好的方法,我很乐意支持/接受这些。因为我的解决方案是将display:flex 放到网格上。
    • 向你致敬,因为你没有把答案留给自己,而是把它放在那里。
    猜你喜欢
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多