【问题标题】:How to make the height of the mat-form-field-underline 0 in Angular 6+如何在Angular 6+中使mat-form-field-underline 0的高度
【发布时间】:2019-07-12 13:16:44
【问题描述】:

我目前正在使用 angular 7 处理有角度的材料。我们如何调整 mat-form-field-underline 的高度,从而进一步在选择框周围提供 边框。

<mat-form-field>
    <mat-select>
        <mat-option *ngFor="let type of types" [value]="type.value">{{type.viewValue}}</mat-option>
    </mat-select>
</mat-form-field>

我尝试使用:

.link-1 .mat-form-field-underline{ 
    height: 0px !important;
}

这里的 link-1 是父分区。但我没有发现任何区别。

谢谢。

【问题讨论】:

  • 请看我更新的答案

标签: css angular typescript angular7


【解决方案1】:

试试下面的。基本上你需要使用::ng-deep

// You can use /deep/ also
::ng-deep .mat-form-field-underline {
  // background: red !important;
  height: 0 !important;
}

如果您对弃用警告感到困扰,您可以将 ViewEncapsulation 设置为 None ,如下所示

    import {Component, ViewEncapsulation} from '@angular/core';

    @Component({
      selector: 'form-example',
      templateUrl: 'form-example.html',
      styleUrls: ['form-example.css'],
      encapsulation: ViewEncapsulation.None
    })

    .mat-form-field-underline {
     height: 0 !important;
     }

【讨论】:

  • ::ng-deep 不再支持 Angular 6+ 版本。我害怕。
  • @Shubham,是的,在他们找到替代品之前,它会被弃用。警告只是为了让我们意识到这一点。您现在可以使用它。
  • 利用 "encapsulation" 属性对我有用,但这带来了一种新的问题.. 整个部门转移到底部,好像他们给了所有子元素的填充。努力受到赞赏。我遇到的另一个非常适合我的解决方案是使用 @Component 的 "Styles" 属性。看看下面的代码:styles: [':host/deep/ &lt;here goes the styles inc. {}&gt;']
  • /deep/::ng-deep 的替代品。那么,我的一个解决方案对你有用吗?
  • /deep/::ng-deep 的替代品。从技术上讲,Angular 6+ 版本不支持 ::ng-deep。但是,是的.. 你可以说,你的解决方案之一有效!
猜你喜欢
  • 1970-01-01
  • 2022-07-25
  • 2019-07-12
  • 2019-02-08
  • 2018-09-27
  • 2019-02-18
  • 2020-10-26
  • 2018-04-16
  • 2020-03-27
相关资源
最近更新 更多