How to overwrite angular-material2 styles?

自作多情 提交于 2019-12-03 20:17:00

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.

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