Style html,body from web component (Angular 2)

前端 未结 10 1765
南笙
南笙 2020-12-03 00:39

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

相关标签:
10条回答
  • 2020-12-03 01:15

    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"] 
                } 
            } 
        } 
    }
    
    0 讨论(0)
  • 2020-12-03 01:18

    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.

    0 讨论(0)
  • 2020-12-03 01:22

    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');
          }
    
    0 讨论(0)
  • 2020-12-03 01:23

    I just edited the styles.scss file and it worked for me.

    0 讨论(0)
提交回复
热议问题