[英]CSS From Parent Component Not Applying to Child Component Angular 9
I have a component nested within a component with a bunch of HTML.我有一个组件嵌套在一个包含一堆 HTML 的组件中。 In the parent component, I am trying to have the CSS written there apply to the nested component.
在父组件中,我试图让写在那里的 CSS 适用于嵌套组件。
Example:例子:
/* this is within the parent css */
button{
color: red;
}
But then in the child the component's button is not red.但是在子组件中,组件的按钮不是红色的。
I am linking the components like so:我正在像这样链接组件:
<!-- this is within the HTML of the parent -->
<div>
<nested-component></nested-component>
</div>
You can prepend :host::ng-deep
to achieve this.您可以预先添加
:host::ng-deep
来实现这一点。
:host ::ng-deep button {
color: red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.