本文介绍了从fxLayoutGap删除行的最后一个元素的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用fxLayoutGap时遇到问题.我列表的最后一列有填充,我不想要.
I have a problem using fxLayoutGap. The last column of my list has a padding and I don't want it.
如何保留fxLayoutGap(卡之间的空间)并从最后一列中删除填充?谢谢!
How to keep fxLayoutGap (space between cards) and remove the padding from the last column ? Thank !
<div fxFlexFill fxLayout="row wrap" fxLayout.xs="column" fxLayout.sm="column" fxLayoutGap="20px grid" style="margin-right:-20px;">
<div fxHide.lt-sm="true" fxFlex="calc(25%-20px)" fxFlex.md="33">
<div fxFlexFill fxLayoutAlign="center center">
<mat-card (click)="addAdvert()" class="mat-card-add-button">
<div fxLayout="row" fxLayoutAlign="center center" fxFlex="100%">
<span style="font-size:32px;text-align:center">+<br />test</span>
</div>
</mat-card>
</div>
</div>
<div fxFlex="calc(25%-20px)" fxFlex.md="33" *ngFor="let product of products | slice:0:3">
<div style="border:1px solid #ccc" fxFlexFill fxLayoutAlign="center stretch">
<mat-card class="ad">
<img mat-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
<mat-card-title>test</mat-card-title>
<mat-card-content>
<p>test</p>
</mat-card-content>
<mat-divider [inset]="true"></mat-divider>
<mat-card-actions align="end">
<button mat-icon-button matTooltip="edit" matTooltipShowDelay="800">
<mat-icon>mode_edit</mat-icon>
</button>
<button mat-icon-button matTooltip="delete" matTooltipShowDelay="800">
<mat-icon>delete</mat-icon>
</button>
</mat-card-actions>
</mat-card>
</div>
</div>
</div>
问题(红色):
更新
我使用了 Abdul Rafay's 的解决方案,但这是一个新问题:
I used Abdul Rafay's solution but here a new problem:
推荐答案
编辑:尝试通过ngFor
在此处为元素分配类:
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"
}
}
然后添加以下css
样式:
.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.
旧ans :只需添加css
样式:
[fxFlex]:last-of-type { padding-right:0px !important; }
如果有不止一行:
[fxFlex]:nth-child(4n) { padding-right:0px !important; }
如果fxFlex元素更多,则可以分配一个类:
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; }
这篇关于从fxLayoutGap删除行的最后一个元素的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!