有没有办法在Angular2组件中的ng-content中使用css?
发布时间:2020-12-17 17:32:41 所属栏目:安全 来源:网络整理
导读:我尝试通过ng-content包含组件中包含的css for children元素.它似乎尚未在Angular 2中实现,或者除了将css放在一般样式表中之外,有人可能有解决方案? app.component.ts comp-parent comp-child/comp-child/comp-parent compParent.component.html div class=
我尝试通过ng-content包含组件中包含的css for children元素.它似乎尚未在Angular 2中实现,或者除了将css放在一般样式表中之外,有人可能有解决方案?
app.component.ts <comp-parent> <comp-child></comp-child> </comp-parent> compParent.component.html <div class="wrapper"> <ng-content></ng-content> </div> compParent.component.css .wrapper > comp-child { margin-right: 5px; <-- Not applied !!! } 解决方法
您可以使用/ deep /(已弃用)或>>>或:: ng-deep选择器:
https://angular.io/guide/component-styles#deprecated-deep–and-ng-deep 例如.: .wrapper ::ng-deep comp-child { ... } 请注意,>>>似乎不适用于基于angular-cli的项目. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |