微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – 如何使用Angular更改最外层标记的背景颜色

我想以编程方式更改Angularapp的背景颜色.这里的问题是,更改应用程序内部的背景,仅适用于屏幕的某些部分.可能只是已经填充内容内容.我希望整个网站改变颜色.

我正在使用angular.io提供的种子. index.html看起来像这样:

<!DOCTYPE html>
<html>
    <head>
        <base href="/">
        <title>Angular QuickStart</title>
        <Meta charset="UTF-8">
        <Meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="stylesheet" href="styles.css">
        <!-- polyfill(s) for older browsers -->
        <script src="node_modules/core-js/client/shim.min.js"></script>
        <script src="node_modules/zone.js/dist/zone.js"></script>
        <script src="node_modules/systemjs/dist/system.src.js"></script>
        <script src="systemjs.config.js"></script>
        <script>
            System.import('app').catch(function (err) { console.error(err); });
        </script>
    </head>
  <body>
    <my-app>Loading AppComponent content here ...</my-app>
  </body>
</html>

有没有办法从Angularapp操纵最外层“body”的类?

我可以更改“my-app”中的所有内容标记.有没有办法以第一个“body”标签在我的控制中的方式设置index.html?

如果没有,是否有另一种方法来控制外部“身体”标签

提前致谢!

BR Mathias

解决方法

组件中有一种更简单的方法

@Component({
    selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})
export class AppComponent {

    constructor() {
        document.body.style.background = 'rgba(0,.6)';
    }

}

或者在src / styles.css中使用简单的CSS

body {
    background: whatever;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐