首页 文章

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

提问于
浏览
3

我创建了3个组件 .

  • login

  • forgot-pass

  • customer

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

<app-login></app-login>
<app-forgot-pass></app-forgot-pass>
<app-customer></app-customer>

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

enter image description here

Here is issue: 当我们在滚动时到达客户 component 时,应显示fab按钮,但是对于所有组件都可以看到它,这意味着fab按钮溢出 customer 组件,如下图所示:

enter image description here

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

这是stackblitz链接 .

1 回答

  • 2

    尝试添加位置 relativeabsolute

    这是一个例子

    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>
    

    customer.component.css

    .mainDiv{
      position: relative;
    }
    #add-button{
    
      right: 20px;
      bottom: 10px;
      left: auto;
      position: absolute;
    }
    

    这是一个更新的Stackblitz

相关问题