In looking at Polymer, I see the following CSS selector in the Styles tab of Chrome 37's developer tools:
I've also seen a selector with pseudo selector ::shadow
.
So, what do /deep/
and ::shadow
in a CSS selector mean?
::ng-deep selectorThe ::ng-deep combinator works to any depth of nested components, and it applies to both the view children and content children of the component. The following example targets all <h3> elements, from the host element down through this component to all of its child elements in the DOM.
CSS Shadow Parts allow developers to style CSS properties on an element inside of a shadow tree. This is extremely useful in customizing Ionic Framework Shadow DOM components.
The :host CSS pseudo-class selects the shadow host of the shadow DOM containing the CSS it is used inside — in other words, this allows you to select a custom element from inside its shadow DOM.
Shadow DOM allows hidden DOM trees to be attached to elements in the regular DOM tree — this shadow DOM tree starts with a shadow root, underneath which you can attach any element, in the same way as the normal DOM.
As Joel H. points out in the comments, Chrome has since deprecated the /deep/
combinator, and it gives a syntax error in IE.
HTML5 Web Components offer full encapsulation of CSS styles.
This means that:
However sometimes you want to have page-level rules to manipulate the presentation of component elements defined within their shadow DOM. In order to do this, you add /deep/
to the CSS selector.
So in the example shown, html /deep/ [self-end]
is selecting all elements under the html
(top level) element that have the self-end
attribute, including those buried inside web components' shadow DOMs roots.
If you require a selected element to live within a shadow root, then you can use the ::shadow
pseudo selector on its parent element.
Consider:
<div> <span>Outer</span> #shadow-root <my-component> <span>Inner</span> </my-component> </div>
The selector html /deep/ span
will select both <span>
elements.
The selector ::shadow span
will select only the inner <span>
element.
Read more about this in the W3C's CSS Scoping Module specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With