简体   繁体   English

如何停止 ion-text-nowrap 打破离子卡内的离子网格

[英]How to stop ion-text-nowrap break ion-grid inside ion-card

I have a grid that has one row, and use ngFor to loop multiple column for each cell.我有一个只有一行的网格,并使用 ngFor 为每个单元格循环多列。 Inside each cell first row will be ion-item wrap a thumbnail and the label.在每个单元格的第一行内,离子项包裹一个缩略图和 label。 Below there are 1 row with 2 col.下面有 1 行,2 列。 Example code.示例代码。

<ion-grid>
    <ion-row>      
      <ion-text color="primary"><h1>Title</h1></ion-text>
    </ion-row>
    <ion-row>
      <ion-col *ngFor="let s of sList">
        <ion-card>
          <ion-row>
            <ion-item>
              <!--  picture -->
              <ion-thumbnail slot="start">
                <img alt="Silhouette of mountains" src="https://ionicframework.com/docs/demos/api/thumbnail/thumbnail.svg" />
              </ion-thumbnail>
              <ion-label>id : </ion-label>
            </ion-item>
          </ion-row>
          <ion-row >
            <ion-col >         
                <div class="ion-text-nowrap">This is content left</div>
            </ion-col>
            <ion-col >            
                <div class="ion-text-nowrap">This is content right</div>
            </ion-col>
          </ion-row>
        </ion-card>
      </ion-col>
    </ion-row>
 </ion-grid>

My problem is on desktop mode(1440x1062), after adding the ion-text-nowrap attribute the column explanded to whole row and forced the another column inside the row wrap below like this.我的问题是在桌面模式(1440x1062)上,添加 ion-text-nowrap 属性后,列被解释为整行,并像这样在下面的行中强制另一列换行。

在此处输入图像描述

But what I want to achieve is something like this, and the code above works but only in mobile range,但我想要实现的是这样的,上面的代码有效,但只在移动范围内,

在此处输入图像描述

once it gets to tablet range(768px) the problem mentioned above appeared.一旦到达平板电脑范围(768px),就会出现上述问题。

How can make sure the text-no-wrap won't effects the tablet view and making sure those 2 column stay shoulder to shoulder?如何确保 text-no-wrap 不会影响平板电脑视图并确保那些 2 列并肩保持?

I found the answer now, It has to do with setting the col size.我现在找到了答案,这与设置 col 大小有关。 For some reason, ion-col size attribute auto is different from not setting one.出于某种原因, ion-col 大小属性 auto 与不设置一个不同。 The difference seems to be:区别似乎是:

set size auto -设置大小自动 -

  • set a same dynamic size for each col为每个列设置相同的动态大小

not setting a size auto -不设置大小自动 -

  • set different dynamic size for different col为不同的col设置不同的动态大小

so the code will be like this:所以代码将是这样的:

<ion-col size="auto" *ngFor="let s of sList">
    <ion-card >
        <ion-row>
            <ion-item>
              <ion-thumbnail slot="start">
                <img alt="Silhouette of mountains" src="https://ionicframework.com/docs/demos/api/thumbnail/thumbnail.svg" />
              </ion-thumbnail>
              <ion-label>label</ion-label>
            </ion-item>
          </ion-row>
          Small title --
          <ion-row>
            <ion-col><div class="ion-text-nowrap">a__item : xxxx</div></ion-col>
            <ion-col><div class="ion-text-nowrap">b____item xxxx</div></ion-col>
          </ion-row>
          <ion-row>
            <ion-col><div class="ion-text-nowrap">a__item : xxxx</div></ion-col>
            <ion-col><div class="ion-text-nowrap">b____item xxxx</div></ion-col>
          </ion-row>
        </ion-card>
</ion-col>

Now the col won't expand whole row, each col has same size.现在 col 不会扩展整行,每个 col 具有相同的大小。 And the text won't auto wrap.并且文本不会自动换行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM