Using fxLayoutGap and wrap leaves an annoying margin at the end of each row that is wrapped.
Is there a way to fix this?
https://stackblitz.com/edit/angular-fxlayoutgap-calc-mralnz?file=app%2Fapp.component.html
<div fxLayout="row wrap" fxLayoutGap="25px">
<mat-form-field fxFlex.xs="calc(50%-25px)" fxFlex="calc(33%-25px)">
<input matInput placeholder="Name">
</mat-form-field>
<mat-form-field fxFlex.xs="calc(50%-25px)" fxFlex="calc(33%-25px)">
<input matInput placeholder="Occupation">
</mat-form-field>
<mat-form-field fxFlex.xs="calc(50%-25px)" fxFlex="calc(33%-25px)">
<input matInput placeholder="Company">
</mat-form-field>
<mat-form-field fxFlex.xs="calc(50%-25px)" fxFlex="calc(33%-25px)">
<input matInput placeholder="Name">
</mat-form-field>
<mat-form-field fxFlex.xs="calc(50%-25px)" fxFlex="calc(33%-25px)">
<input matInput placeholder="Occupation">
</mat-form-field>
<mat-form-field fxFlex.xs="calc(50%-25px)" fxFlex="calc(33%-25px)">
<input matInput placeholder="Company">
</mat-form-field>
</div>
I am using:
For anyone looking for the answer to this problem, you need to add grid to fxLayoutGap. The documentation at https://github.com/angular/flex-layout/wiki/fxLayoutGap-API states:
To use fxLayoutGap with a gutter system, simply append the suffix grid to any fxLayoutGap value. This creates a gutter system by applying a margin to the host element and an inverse padding to each child. Other than this change, it works exactly as the default mode. It also takes flex-order and hidden elements into account, and has the same responsive abilities as the default mode.
Please note that unlike the standard gap functionality, fxLayoutGap with the grid keyword applies a padding to each child element to add the gutter, in addition to the margin on the host element.
That last point is in relation to how the grid on the child elements can clash with the fxLayoutGap on the parent element so be aware that the parent may override the child layout. Adding an extra div between the two will solve that issue.