Remove padding from fxLayoutGap last element of row

爷,独闯天下 提交于 2019-12-02 00:36:20

Edit: try assigning classes to your elements through ngFor here:

<div fxFlexFill fxLayout="row wrap" fxLayout.xs="column" fxLayout.sm="column" fxLayoutGap="20px grid" style="margin-right:-20px;">
  <div fxFlex="calc(25%-20px)" fxFlex.md="33"
    *ngFor="let product of products;let i = index"
    [ngClass]="'product-'+getClassName(i)">
    ...

.ts:

  counter: number = 0;

  getClassName(index) {
    if(index%4 === 0)
      this.counter = 0;
    this.counter++;
    switch(this.counter) {
      case 1:
        return "first"
      case 2:
        return "second"
      case 3:
        return "third"
      default:
        return "fourth"
    }
  }

then add these css styles:

.product-first[fxFlex] {
  padding-right: 20px !important;
}
.product-second[fxFlex] {
  padding-left: 6.66px !important;
  padding-right: 13.34px !important; 
}
.product-third[fxFlex] {
  padding-left: 13.34px !important;
  padding-right: 6.66px !important;
}
.product-fourth[fxFlex] {
  padding-left: 20px !important;
  padding-right: 0 !important;
}

I'm not sure if it's the best way but it works.

Old ans: Simply add a css styles:

[fxFlex]:last-of-type { padding-right:0px !important; }

If there's more than one row:

[fxFlex]:nth-child(4n) { padding-right:0px !important; }

If there's more fxFlex elements, you can assign a class:

<div fxFlexFill fxLayout="row wrap" fxLayout.xs="column" fxLayout.sm="column" fxLayoutGap="20px grid" style="margin-right:-20px;">
    <div class="padding-fix" fxHide.lt-sm="true" fxFlex="calc(25%-20px)" fxFlex.md="33">
    ...

.padding-fix[fxFlex]:nth-child(4n) { padding-right:0px !important; }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!