/deep/, >>>, and ::ng-deep “shadow-piercing” combinator can be used to force a style down to child components.
These selectors disable view encapsulation for specific CSS rules. In other words, it gives you access to DOM elements, which are not in your component's HTML.
Any style with ::ng-deep applied becomes a global style.
because stackoverflow said so!
legacy code has it :(
what else am I supposed to do?
As the name implies, deep piercing is involved.
The parent defines the styles of the child component.
As the name implies, context of the 'host' matters.
Styles of the child component are defined by itself, based on which parent it is in.
<mat-button-toggle-group #group="matButtonToggleGroup" value='row-container'>
<mat-button-toggle value="row-container" aria-label="Flex direction row" class="toggle-row">
<mat-icon>table_rows</mat-icon>
</mat-button-toggle>
<mat-button-toggle value="column-container" aria-label="Flex direction column" class="toggle-column">
<mat-icon class="column">table_rows</mat-icon>
</mat-button-toggle>
</mat-button-toggle-group><article [ngClass]=[group.value]>
<app-list></app-list>
</article>
<h2>List of cute dogs!</h2>
<mat-card class="example-card">
<mat-card-header class="unicorn--mat-card-header__long-text">
<div mat-card-avatar class="example-header-image"></div>
<mat-card-title>Shiba Inu</mat-card-title>
<mat-card-subtitle>Dog Breed</mat-card-subtitle>
<mat-icon>favorite</mat-icon>
</mat-card-header>
<img
mat-card-image
src="https://material.angular.io/assets/img/examples/shiba2.jpg"
alt="Photo of a Shiba Inu"/>
<mat-card-content>
<p>
The Shiba Inu is the smallest of the six original and distinct spitz
breeds...
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>LIKE</button>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>
// using ng-deep for child components
.row-container {
::ng-deep app-list {
background-color: $blue-chill;
flex-direction: row;
h2 {
display: none;
}
}
}
.column-container {
::ng-deep app-list {
background-color: $tabasco;
flex-direction: column;
}
}<div [ngClass]=[group.value]>
<app-list></app-list>
</div>
:host-context(.row-container) {
background-color: $vista-blue;
flex-direction: row;
h2 {
display: none;
}
}
:host-context(.column-container) {
background-color: $tabasco;
flex-direction: column;
}<mat-card-header class="unicorn--mat-card-header__long-text">
<div mat-card-avatar class="example-header-image"></div>
<mat-card-title>Shiba Inu</mat-card-title>
<mat-card-subtitle>Dog Breed</mat-card-subtitle>
<mat-icon>favorite</mat-icon>
</mat-card-header>// ng-deep for material overrides
::ng-deep .mat-card-header-text {
flex-grow: 2;
}using ::ng-deep
<mat-card-header class="unicorn--mat-card-header__long-text">
<div mat-card-avatar class="example-header-image"></div>
<mat-card-title>Shiba Inu</mat-card-title>
<mat-card-subtitle>Dog Breed</mat-card-subtitle>
<mat-icon>favorite</mat-icon>
</mat-card-header>// global.scss
.unicorn--mat-card-header__long-text {
.mat-card-header-text {
flex-grow: 2;
}
}
without using ::ng-deep()