[英]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,所以希望我包含获得一些帮助所需的一切。
import { Component } from '@angular/core'; @Component({ selector: 'crate', templateUrl: './app/folderA/folderAB/crate.html', styleUrls: ['./app/folderA/folderAB/crate.css'] }) export class MyComponent {}
<div class="background"> <div class="content"> <p>Content</p> </div> </div>
:host-context(.lg){ width: 100%; background-color: #000; border-radius: 25px; }
example.component
.
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? 我做错了什么/错过了什么?
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.