【发布时间】:2021-01-23 06:30:42
【问题描述】:
我有一个项目网格,当我单击其中一个时,我想显示另一个组件,该组件占据所单击项目下行的所有宽度。
我有一个按钮列表组件,其中包含一个按钮组件,它使用 ngFor 显示我的项目。 当我点击一个项目时,尺寸选择组件会显示一个 ngIf。
我的问题是,如果我在按钮列表组件中有大小选择组件,它会附加在网格的末尾,如果我在按钮组件中有这个新组件,那么它只需要包含被点击项的列的宽度。
如果我把它放在绝对位置,我可以使它成为容器的宽度,但是以下项目不会下降。
这是我的一段代码
按钮列表
<div class="wrapper">
<div class="container">
<app-button *ngFor="let button of buttons;" [button]="button" (buttonClicked)="onButtonClicked($event)">
</app-button>
</div>
</div>
.container {
position: relative;
display: grid;
grid-template-columns: repeat(3, minmax(250rem, 1fr));
grid-gap: 10rem;
place-items: start center;
overflow-x: hidden;
overflow-y: auto;
margin: 10rem;
}
按钮
<div class="product">
<div class="product-col">
<h2 class="product_title" (click)="onButtonClicked()">{{button.Caption}}</h2>
<img class="product_img" [src]="picture" alt="" (click)="onButtonClicked()">
<span class="product_price" *ngIf="button.Price && button.Price != '0'">{{button.Price / 100 | currency}}</span>
</div>
</div>
<app-size-selection-button-list *ngIf="isSizeSelectionOpen"></app-size-selection-button-list>
如何才能做到这一点?也许 CSS 中有一个解决方案,或者可能有另一种方法可以将我的组件插入到可行的项目网格中。
谢谢
【问题讨论】: