如何在mat-h orizo ntal-stepper中为不同形式设置不同的宽度

问题描述 投票:0回答:1

我想在mat-step中为不同的形式设置不同的宽度。第一种形式的内容为宽度为400px,第二种形式的内容为宽度为700px。

<mat-horizontal-stepper labelPosition="bottom" #stepper>
  <mat-step [stepControl]="firstFormGroup">
    <form [formGroup]="firstFormGroup">
      <ng-template matStepLabel>Fill out your name</ng-template>
       <div style="width:400px">
 <mat-form-field>
        <input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
      </mat-form-field>

       </div>

      <div>
        <button mat-button matStepperNext>Next</button>
      </div>
    </form>
  </mat-step>
  <mat-step [stepControl]="secondFormGroup">
    <form [formGroup]="secondFormGroup">
      <ng-template matStepLabel>Fill out your address</ng-template>
      <div style="width:700px">
         <mat-form-field>
        <input matInput placeholder="Address" formControlName="secondCtrl" required>
      </mat-form-field>
      </div>


      <div>
        <button mat-button matStepperPrevious>Back</button>
        <button mat-button matStepperNext>Next</button>
      </div>
    </form>
  </mat-step>
  <mat-step>
    <ng-template matStepLabel>Done</ng-template>
    You are now done.
    <div>
      <button mat-button matStepperPrevious>Back</button>
      <button mat-button (click)="stepper.reset()">Reset</button>
    </div>
  </mat-step>
</mat-horizontal-stepper>

但它不起作用,任何人都可以帮助我如何实现这一目标。

css sass angular6 angular-material-6
1个回答
0
投票

由于只有mat-step components的可见性正在改变,你应该覆盖不可见的宽度。

CSS文件中使用以下代码:

::ng-deep .mat-horizontal-stepper-content[aria-expanded="false"] {
  width: 0px !important;
}

使用此功能后,您可以为每个步骤使用不同的宽度尺寸。

© www.soinside.com 2019 - 2024. All rights reserved.