Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why child component styles overwriting by global css?

Tags:

css

angular

I am importing a base css file in my index.html that includes width as auto, but this style is taking priority over the style I define in components(used width as 70%) using styleUrls: ["..."]. What is the best way to make sure that my component-scoped css takes priority over styling defined the traditional way? Should I have my global styles scoped to my top level component?

like image 824
Swetha Avatar asked Oct 20 '16 14:10

Swetha


2 Answers

In order to override global scss, simply add below line (encapsulation: ViewEncapsulation.None) in your component.ts file:

  @Component({  selector: 'app-custom-component',
      templateUrl: './custom-component.component.html',
      styleUrls: ['./custom-component.component.scss'],
      encapsulation: ViewEncapsulation.None
    })
like image 139
RohitAneja Avatar answered Nov 16 '22 01:11

RohitAneja


In general css in your component is the one that has priotiry. You can try to use

encapsulation: ViewEncapsulation.None in your app.component.

if you have a class in your component it would have priority.

https://angular.io/docs/ts/latest/guide/component-styles.html

like image 22
Roninio Avatar answered Nov 16 '22 01:11

Roninio