mobile responsive with bootstrap grid and expandab

2019-08-20 19:41发布

I have created a bootstrap grid page and it's working as I want on desktop screen.

My actual problem is when I use mobile, I can't get how to reorder my cards in right way.

Here's my logic

<div class="row">
  <div *ngFor="let col of [1,2]; let index=index" class="col-12 col-sm-6 col-xl-6">
    <div  *ngFor="let card of cards; let indexC=index" class='col-sm-12' >
      <app-expend  [card]="card" *ngIf="indexC%2===index"></app-expend> //card[1] = Hi1
    </div>
  </div>
</div>

The reason why I can't use a row with all colums inside is that When I expand other columns don't shift.

Here's a sample

What I expect is having column on mobile in this order

Hi1                Hi1
Hi2                Hi3
Hi3   Instead of   Hi5
Hi4                Hi2
Hi5                Hi4
Hi6                Hi6

And in desktop ( already done ) :

Hi1  Hi2  
Hi3  Hi4
Hi5  Hi6

the code should looks like something like this

<div class="row">
    <div  *ngFor="let card of cards; let indexC=index" class='col-sm-12' >
      <app-expend  [card]="card"></app-expend> //card[1] = Hi1
    </div>
</div>

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-20 20:42

It works perfectly when applied proper classes like - col-xl-6 col-lg-6 col-md-6 col-sm-12. So your snipper would be -

<div class="row m-2">
    <div *ngFor="let card of cards; let indexC=index" class='col-xl-6 col-lg-6 col-md-6 col-sm-12' >
      <app-expend  [card]="card"></app-expend>
    </div>
</div>

Check it live here, try resizing the output window.

  • Snaps of output -

1. On large screen large screen

2. On small screen

small screen*

查看更多
登录 后发表回答