简体   繁体   English

Angular2 css:主机应用但在浏览器中不可见

[英]Angular2 css :host applying but not visible in browser

I am having a bizarre issue whilst creating my first Angular2 app. 在创建我的第一个Angular2应用程序时,我遇到了一个奇怪的问题。

I am applying some CSS to a component host ( example-component ) yet it doesn't appear in the browser? 我将一些CSS应用于组件主机example-component )但它没有出现在浏览器中?

This is my first time posting for Angular in SO, so hopefully I include everything needed to attain some help. 这是我第一次在SO中发布Angular,所以希望我包含获得一些帮助所需的一切。


example.component.ts example.component.ts

 import { Component } from '@angular/core'; @Component({ selector: 'crate', templateUrl: './app/folderA/folderAB/crate.html', styleUrls: ['./app/folderA/folderAB/crate.css'] }) export class MyComponent {} 


index.html 的index.html


crate.html crate.html

 <div class="background"> <div class="content"> <p>Content</p> </div> </div> 


crate.css crate.css

 :host-context(.lg){ width: 100%; background-color: #000; border-radius: 25px; } 


What I don't understand, is that I open this in chrome & firefox, and I see the following CSS stated under rules for example.component . 我不明白的是,我在chrome和firefox中打开它,我看到下面的CSS在example.component规则下声明。

 .lg[_nghost-ims-2], .lg [_nghost-ims-2] { width: 100%; background-color: #000; border-radius: 25px; } 

火狐

It is correctly applying the CSS to example-component , but it is not being displayed / rendered in browser. 它正确地将CSS应用于example-component ,但它没有在浏览器中显示/呈现。 What am I doing wrong / missing? 我做错了什么/错过了什么?


EDIT 编辑

The exact same issue applies even if I change crate.css to: 即使我将crate.css更改为:完全相同的问题也适用于:

 crate{ width: 100%; background-color: #000; border-radius: 25px; } 

Any component with an unrecognized tagName like <crate></crate> is created as a HTMLUnknownElement and has empty values for all the style properties, if you want it to behave like a div then add display: block; 具有无法识别的tagName(如<crate></crate> )的任何组件都将创建为HTMLUnknownElement,并且所有样式属性都具有空值,如果您希望它的行为类似于div则添加display: block; to your stylesheet. 到你的样式表。

See Browsers' default CSS for HTML elements for additional resources on the default css for different browsers. 有关不同浏览器的默认css上的其他资源,请参阅浏览器的HTML元素默认CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM