【发布时间】:2019-11-14 20:37:42
【问题描述】:
我添加了::ng-deep 组合器,用于在我的组件中引用内容投影元素。但是当我从默认(ViewEncapsulation.Emulated)切换到ViewEncapsulation.ShadowDom 模式时,显然::ng-deep 不是本机Shadow DOM 选择器,旧的CSS 不起作用。
/* This works in ViewEncapsulation.Emulated */
:host ::ng-deep .course-description {
max-width: 360px;
margin: 0 auto;
margin-top: 15px;
user-select: none;
}
令人惊讶的是,当我在 Chrome v75.0.3770.100 中使用 /deep/ 组合器(在 Chrome v63 中删除 https://developers.google.com/web/updates/2017/10/remove-shadow-piercing)时,ViewEncapsulation.ShadowDom 工作正常
/* This works in ViewEncapsulation.ShadowDom */
:host /deep/ .course-description {
max-width: 360px;
margin: 0 auto;
margin-top: 15px;
user-select: none;
}
是否可以在组件 CSS 中使用 ::slotted() 使其像以前一样工作但在 ViewEncapsulation.ShadowDom 模式下工作?如果是,怎么做?
【问题讨论】:
标签: css angular shadow-dom