![](/img/trans.png)
[英]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.