How to overwrite angular-material2 styles?

試著忘記壹切 提交于 2019-12-21 05:38:16

问题


I'm using Angular2 with Material Design Components. And would like to overwrite some styles, but it looks like it's not possible because of ViewEncapsulation.

Is it possible to switch off ViewEncapsulation(ViewEncapsulation.None) for 3rd party components?


回答1:


I personally wouldn't touch the actual third party source ( like changing the encapsulation ) and reason is their style might mess up.

But to handle this , I give you couple of solutions :

1-- Ugly :

You can override whatever you want from a component ( probably your top level component ) if it's viewEncapsulation is none .

So go to your app.ts and change the encapsulation to none and the do what ever you want inside that :

  inside your app.scss or css

    md-input {

       input { color:red} 

     // or whatever style you want to override , sometimes you'll need !important .
    }

2-- Better :

Material has some variables.scss file that you'll fine in their source and you can easily override their variables , like colors and stuff .

In general, you can override a global css only if the component that your doing the overriding from , it's encapsulation is none , otherwise your styles wont go outside of that component.



来源:https://stackoverflow.com/questions/38550969/how-to-overwrite-angular-material2-styles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!