css - 来自父组件的CSS不适用于子组件Angular 9
问题描述
我有一个组件嵌套在带有一堆 HTML 的组件中。在父组件中,我试图将那里编写的 CSS 应用于嵌套组件。
例子:
/* this is within the parent css */
button{
color: red;
}
但是在子组件中,组件的按钮不是红色的。
我正在像这样链接组件:
<!-- this is within the HTML of the parent -->
<div>
<nested-component></nested-component>
</div>
解决方案
您可以预先:host ::ng-deep
实现这一目标。
:host ::ng-deep button {
color: red;
}
推荐阅读
- javascript - 限制每个 ID 的昵称数量
- julia - 是否有一个函数可以让我控制 var args 的数量?
- byte-buddy - 字节伙伴在多个仪器之间共享变量
- r - R - 计算字符串中的连续字母
- c# - 使用可寻址对象在 Unity 游戏中加载许多独特精灵时的内存问题
- python - 过滤器损坏。代码应该只移动具有 2 个大写字母的电子邮件地址的帐户
- regex - 如何获得以两个字符之一结尾的字符串并用正则表达式有条件地替换最后一个字符?
- python - MongoDB - pymongo.errors.DocumentTooLarge 错误
- javascript - 将变量传递给 NodeJS 需要设置?
- php - 即使属性在排除数组中,TrimStrings 中间件也会继续修剪