Styles of my root component are not applied in my Angular app

1621 views css
8

I was trying to apply a style to my app-root, however it's not being applied, please consider this stackblitz example https://stackblitz.com/edit/angular-zkmfcp

In my app-component I have

app-root {
  background: red;
}

What am I missing? (Im very new to Angular...)

answered question

Styles within a components CSS are only applies within that component. In this case, the app-root tag is not within the app.component.html file

1 Answer

10

read this article

try:

:host {
 background-color: red;
}

or based on comment @user184994 said Styles within a components CSS are only applies within that component. In this case, the app-root tag is not within the app.component.html, so you should add it to global css file add:

app-root {
  background-color: red;
}

to your style.css file of src folder.

your DEMO

posted this

Have an answer?

JD

Please login first before posting an answer.