Skip to content

Commit 7367aca

Browse files
docs(common): Explain how ::ng-deep works
Co-authored-by: Matthieu Riegler <[email protected]>
1 parent 8f3fdc3 commit 7367aca

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

adev/src/content/guide/components/styling.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ as `::shadow` or `::part`.
7171

7272
#### `::ng-deep`
7373

74-
Angular's emulated encapsulation mode supports a custom pseudo class, `::ng-deep`. Applying this
75-
pseudo class to a CSS rule disables encapsulation for that rule, effectively turning it into a
76-
global style. **The Angular team strongly discourages new use of `::ng-deep`**. These APIs remain
74+
Angular's emulated encapsulation mode supports a custom pseudo class, `::ng-deep`.
75+
**The Angular team strongly discourages new use of `::ng-deep`**. These APIs remain
7776
exclusively for backwards compatibility.
7877

78+
When a selector contains `::ng-deep`, Angular stops applying view-encapsulation boundaries after that point in the selector. Any part of the selector that follows `::ng-deep` can match elements outside the component’s template.
79+
80+
For example:
81+
- a CSS rule selector like `p a`, using the emulated encapsulation, will match `<a>` elements that are descendants of a `<p>` element,
82+
both being within the component's own template.
83+
- A selector like `::ng-deep p a` will match `<a>` elements anywhere in the application, descendants of a `<p>` element anywhere in the application.
84+
That effectively makes it behave like a global style.
85+
- In `p ::ng-deep a`, Angular requires the `<p>` element to come from the component's own template, but the `<a>` element may be anywhere in the application.
86+
So, in effect, the `<a>` element may be in the component's template, or in any of its projected or child content.
87+
- With `:host ::ng-deep p a`, both the `<a>` and `<p>` elements must be decendants of the component's host element.
88+
They can come from the component's template or the views of its child components, but not elsewhere in the app.
89+
7990
### ViewEncapsulation.ShadowDom
8091

8192
This mode scopes styles within a component by

0 commit comments

Comments
 (0)