html - 如何增加 Angular Material 中 mat-select 表单的宽度?

标签 html css angular

我正在尝试根据可用空间动态增加垫选择表单的宽度,同时将表单标题保持在左侧。我下面的解决方案增加了表单的宽度,但将标题放在表单上方而不是左侧。

下拉样式:

mat-form-field {
  width: 100%;
}

html:

<span style="font-size: large; "> Subject Area </span>
<mat-form-field>
     <mat-label>Select a Subject Area</mat-label>
     <mat-select>
         <mat-option *ngFor="let subjectArea of subjectAreas" [value]="subjectArea.value">
             {{subjectArea.viewValue}}
         </mat-option>
     </mat-select>
</mat-form-field>

编辑: 标题现在位于表单的左侧,但正在换行。网页上有足够的空间将所有标题排成一行。这是由于 Material 网格列表在页面中央组织了三个单独的表格吗? New Issue

最佳答案

看看这个 Blitz :https://stackblitz.com/edit/angular-mat-select-example-icf9op

想法很简单:将您的 mat-form-field 元素包裹在一个容器中并将容器的显示设置为 flex。

<div class="form-field-group">
 <span class="form-field-label">Your Country:</span>
   <mat-form-field>
      <mat-label>Country:</mat-label>
     <mat-select name="countryString" [(value)]="selectedCountry">
        <mat-option [value]="'GB'">Great Britain</mat-option>
        <mat-option [value]="'US'">United States</mat-option>
        <mat-option [value]="'CA'">Canada</mat-option>
      </mat-select>
    </mat-form-field>
  </div>

以及让它工作的 SCSS:

.form-field-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  .form-field-label {
    white-space: nowrap;
  }
  .form-field-label + mat-form-field {
   margin-left: 10px;
  }
  mat-form-field {
    width:100%;
  }
}

关于html - 如何增加 Angular Material 中 mat-select 表单的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59416790/

相关文章:

html - Wordpress 移动菜单不工作和标题文本跳转

css - 手动创建的按钮的默认大小

angular - 'value' 应该是 Kendo Angular DatePicker 中有效的 JavaScript Date 实例

angular - 如何使用 indexedDB 的 promise 在@ngrx/core 中设置initialState

html - firefox中滚动条的css问题

javascript - 流程图 : change the axis data type to time

html - css3 翻译添加更多的高度和宽度

html - 绝对定位的 div 不会一直延伸到 body 下方

android - 直接从 Android 文件管理器打开 html 页面时如何正确设置背景图像的绝对路径

javascript - 以相同方式处理所有http错误