angular - 如何以角度将自定义css添加到库组件?
问题描述
我正在使用带有材料设计的 Angular 9.0。
在组件中,我想使用<mat-tab-group>
数组并将其样式设置为某种颜色和设计。
我知道两种方法:
- 使用
::ng-deep
但现已弃用 - 使用全局
css
样式表,但在任何地方都应用它
我只想在该组件中包含的选项卡上执行此操作。
<mat-tab label="myList">
<div>
<app-lister-search></app-lister-search>
</div>
<div>
<app-lister></app-lister>
</div>
</mat-tab>
</mat-tab-group>```
this will generate some component, and I want to apply css to some of them, but they is not possible to add this in the component css as it it outside of the scope.
How can I achieve this ?
解决方案
没有什么可以阻止您将样式放在“主”样式表中并将其仅应用于具有特定类的选项卡组:
模板:
<mat-tab-group class="my-tab-group">
<mat-tab label="First"> Content 1 </mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
样式.scss:
.my-tab-group {
background-color: orange;
.mat-tab-label {
padding: 5em;
&-active {
background-color: green;
}
}
}
推荐阅读
- typescript - 如何根据是否在 Typescript 中设置对象属性来定义条件返回类型
- flutter - TextFormField 剪切最后一个字符输入
- javascript - 在 JavaScript 中有效地将 2D 数组转换为擦除重复项的对象
- python - Python中的组合函数
- .htaccess - 如何阻止自定义 url 被重定向到主页?
- python - Python Selenium - WebDriverException:browserContextFn() .currentWindowGlobal 为空
- python - 如何申请 re.sub() 有例外
- java - 在 recyclerview 中滚动时对 Firestore 数据进行分页
- c++ - STB 将 png 加载到 OpenGL 纹理会导致黑色或白色背景
- java - 尽管在 spring /authenticate 令牌生成器端点上有效,但凭据错误