Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: Apply CSS Style with component selector

I'm learning Angular 2 and I wonder if it is possible to apply css style by using the component selector like this:

the component

@Component({
    selector: 'app',
    styleUrl: './local.css',
    templateUrl: './app.html',
})
export class AppComponent { }  

the style

app {
    width: 10px;
    height: 100px;
    background-color: red;
}

Assume it's possible, is it the best way to do that ?

like image 664
Christopher N. KATOYI-KABA Avatar asked Jan 05 '23 05:01

Christopher N. KATOYI-KABA


1 Answers

Use :host instead

:host {
    width: 10px;
    height: 100px;
    background-color: red;
}

Use app when you want to apply styles from outside the component.

like image 115
Günter Zöchbauer Avatar answered Jan 13 '23 10:01

Günter Zöchbauer