修复一个组件中的 mat-fab 按钮

Sha*_*kar 5 css angular-material angular

我创建了 3 个名为的组件。

  1. login

  2. forgot-pass

  3. customer

我已将所有这些组件放置在 中app.component.html,一个在另一个下面,使用相应的选择器,如下所示:

<app-login></app-login>
<app-forgot-pass></app-forgot-pass>
<app-customer></app-customer>
Run Code Online (Sandbox Code Playgroud)

在这里,我在客户组件的右下角添加了一个按钮(mat-fab),如下图所示:

在此输入图像描述

这是问题:当我们滚动到达客户时,应该显示 fab 按钮component,但它对所有组件都是可见的,这意味着 fab 按钮溢出了组件,customer如下图所示:

在此输入图像描述

我认为这是一个CSS问题,我无法弄清楚。

这是stackblitz链接。

Ani*_*had 8

尝试添加位置relative和absolute

这是一个例子

在customer.component.html

<div class="mainDiv">
  <div class="container">
    <div class="customer-search">
    <mat-form-field floatLabel=never >
            <input matInput id="search-com" type="text"  placeholder="search"  >
    </mat-form-field>
    </div>
    <div class="customer-list">
      <mat-selection-list #link>
          <mat-list-option *ngFor="let link of links">
              <a mat-list-item> <span class="customer-names">{{ link }}</span> </a>
          </mat-list-option>
          <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
            {{option}}
          </mat-option>
        </mat-selection-list>
        <button mat-fab color="primary" id="add-button" matTooltip="Add customer"><i class="material-icons" >group_add</i></button>
    </div>

  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

customer.component.css

.mainDiv{
  position: relative;
}
#add-button{

  right: 20px;
  bottom: 10px;
  left: auto;
  position: absolute;
}
Run Code Online (Sandbox Code Playgroud)

这是更新的Stackblitz