I\'m working on a LoginComponent
in Angular 2 that should \"restyle\" the html
and body
tags, so I can put in a background image speci
As an additional update, when using Angular: 9.1.12, adding styling to the body tag can be accomplished by using the src/styles.css file.This is assuming the src/angular.json's projects' architect object's styles array has been set to src/styles.css.
The angular.json file should look similar to below when configuring a global style sheet such as: src/styles.css. There are more details located within the angular documentation as well: https://angular.io/guide/workspace-config#style-script-config
{
"projects": {
"app": {
"architect": {
"styles": ["src/styles.css"]
}
}
}
}
I had same issue with margin-top , the way I fixed is
constructor(
private _renderer: Renderer2,
) {
this._renderer.removeStyle(document.body, 'margin-top');
}
This worked perfectly for me.
I use this approach in my component, loaded in router-outlet:
ngOnInit() {
// Change <body> styling
document.body.classList.add('align-content-between');
}
ngOnDestroy() {
// Change <body> styling
document.body.classList.remove('align-content-between');
}
I just edited the styles.scss file and it worked for me.