首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设计特定材质选择的样式

问如何设计特定材质选择的样式
EN

Stack Overflow用户
提问于 2020-05-07 01:18:33
回答 1查看 442关注 0票数 0

我正在做一个Angular 9项目,使用的是材料。

我有一个页面,它有一些材料选择,和一个材料分页器(它使用一个下拉列表来更改每一页的项目)。我想在分页器的mat select中修改mat选项的样式,但我不希望这影响页面上的其他mat选择。

使用此选项可以编辑页面上的所有mat-select。

代码语言:javascript
复制
::ng-deep mat-option:last-child:before {
  content: "All";
  float: left;
  text-transform: none;
  top: 4px;
  position: relative;
}
::ng-deep mat-option:last-child .mat-option-text {
  display: none;
  position: relative;
}

但是我需要指定只修改分页器select的选项。我试着给mat-paginator添加一个类,但是没有起作用。

代码语言:javascript
复制
<mat-paginator class="myStyleClass" [pageSizeOptions]="[10, 25, dataSource?.filteredData.length]"
      [showFirstLastButtons]="true" (page)="setPaginatorInRoute()" >
    </mat-paginator>

我还做了一个快速的https://stackblitz.com/edit/style-specific-mat-select

有没有办法指定我要设计哪种垫子的样式?

EN

回答 1

Stack Overflow用户

发布于 2020-05-09 13:45:29

ng-deep是不推荐使用的,所以你应该使用没有封装的组件,所以:

代码语言:javascript
复制
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class CustomComponent {}

@Component({
  selector: 'app-custom',
  templateUrl: './custom.component.html',
  styleUrls: ['./custom.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class CustomComponent {}

您创建的css类应该将其封装在另一个类的div中,并以这种方式定义它们:

css

代码语言:javascript
复制
.custom-style-paginator-select {
  mat-option:last-child:before {
    content: "All";
    float: left;
    text-transform: none;
    top: 4px;
    position: relative;
  }
  mat-option:last-child .mat-option-text {
    display: none;
    position: relative;
  }
}

html

代码语言:javascript
复制
<div class="custom-style-paginator-select">
  <mat-paginator class="myStyleClass" [pageSizeOptions]="[10, 25, dataSource?.filteredData.length]" [showFirstLastButtons]="true" (page)="setPaginatorInRoute()" >
  </mat-paginator>
</div>

有关详细信息,请参阅:

https://angular.io/guide/component-styles#view-encapsulation

https://material.angular.io/guide/customizing-component-styles

https://material.angular.io/guide/theming#defining-a-custom-theme

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61641236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档