[英]How to add CSS to Angular Materials component?
I have a web app using angular 2 and angular materials. 我有一个使用角度2和角度材质的Web应用程序。 I am using a simple modal:
我正在使用一个简单的模式:
<h1 md-dialog-title *ngIf="data">{{data.title}}</h1>
<div md-dialog-content>What would you like to do?</div>
<div md-dialog-actions></div>
But when I run the app the modal's height is 100%. 但是,当我运行该应用程序时,模态的高度为100%。 When I inspect with Chrome dev tools, it looks like Angular Materials/Angular 2 is injecting some classes that wrap around the md-dialog-content.
当我使用Chrome开发工具进行检查时,看起来Angular Materials / Angular 2正在注入一些围绕md-dialog-content包裹的类。 Here is a snapshot:
这是快照:
Anyways, does anyone have any suggestion how to override the behavior so I can manually affect the size? 无论如何,有人建议如何覆盖此行为,以便我可以手动影响大小吗? Thanks.
谢谢。
Have you tried opening your dialog with specific height that you need? 您是否尝试过打开所需高度的对话框? like:
喜欢:
let dialogRef = dialog.open(UserProfileComponent, {
height: '400px',
width: '600px',
});
Another way to force custom styles is to customize the theme itself. 强制自定义样式的另一种方法是自定义主题本身。 you can have a look at the guide here .
您可以在这里查看指南。
You can override material styling from your scss/css. 您可以从scss / css覆盖材质样式。 But due to view encapsulation, you need to use /deep/ selector that will allow you to get hold of the Material class added when the component is rendered.
但是由于视图封装,您需要使用/ deep /选择器,该选择器将允许您保留呈现组件时添加的Material类。 For example:
例如:
/deep/ .mat-tab-group.mat-primary .mat-ink-bar{
background-color: red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.