[英]JavaFX CSS: How to inherit background color from other CSS settings?
[英]Angular 6, how to configure CSS settings to create a persisting background color on all components?
我正在尝试创建一种背景色,该背景色将保留在Angular应用程序的所有组件中 。
当我在styles.css
(全局样式表) styles.css
定位html background: blue
,如果我将app.component.ts
上的封装更改为ViewEncapsulation.Native
,则此方法ViewEncapsulation.Native
,但是它覆盖了应用程序中的每个组件。 意味着颜色位于所有其他组件的顶部。
我只想设置背景色,该背景色将位于应用程序中所有组件的后面并保持不变 。
我有同样的问题,并已解决。 我不知道是否是最好的方法,请尝试将它放入index.html
的body标签中:
<body class=".." style="background:#E8EBEE;">
转到您的Style.css或Style.scss文件,并添加以下代码:
body { background: #EEE //Your Background Color that will be shown between all components even if the component fails to load. }
导入Renderer2,如下所示:
import { Component, OnInit, Renderer2 } from '@angular/core';
而且,如果要在使用组件时添加自定义背景,则必须转到component.ts文件,并将此代码添加到构造函数中:
constructor(private renderer: Renderer2) { this.renderer.setStyle(document.body, 'background', '#FFF'); }
该代码仅在加载此组件时才将背景颜色应用于主体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.