请用简单明了的方式解释:host/deep/
的含义:
:host /deep/ .ui-autocomplete {
width: 85%;
}
最佳答案
它用于允许在使用 emulated
时设置子组件的样式查看封装。
可以在这里找到更多相关信息:
https://angular.io/guide/component-styles
顺便说一下 /deep/
选择器现已弃用:
The shadow-piercing descendant combinator is deprecated and support is being removed from major browsers and tools. As such we plan to drop support in Angular (for all 3 of /deep/, >>> and ::ng-deep). Until then ::ng-deep should be preferred for a broader compatibility with the tools.
:host
用于寻址托管元素 - 即您用来在某处添加组件的元素(例如 <app-component>
)。
Use the :host pseudo-class selector to target styles in the element that hosts the component (as opposed to targeting elements inside the component's template).
所以选择器:host /deep/ .ui-autocomplete
表示“在当前托管元素上,深入(也在子组件中搜索)并查找类为 ui-autocomplete
的元素。
这里是一些关于 View 封装特性的附加信息:
https://blog.thoughtram.io/angular/2015/06/29/shadow-dom-strategies-in-angular2.html
关于css - :host/deep/selector mean? 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46914414/