I'm trying to add SASS instead of vanilla CSS to the project and can get it mostly working.
There are no errors or warning messages when building the project. Almost all of the styles are applied after building; however, I use the /deep/ (>>>) special selector in a couple of components to pass a style down to the child component - I do this in order to conditionally apply a style to a specific class in a child component depending on its host/parent component. Here's an example of a style that exists in the host/parent component's stylesheet:
:host >>> .holder {
margin-top: 0px;
padding-top: 12px;
border-top: 2px solid #eee;
}
This is the only style that does not seem to be applied correctly. When viewing the UI locally in any browser, it's clear that the .holder class is not defined as above.
There seems to be much discussion of how to get SASS working in Angular 2 projects on StackOverflow, but nothing relating to SASS (or any other CSS preprocessor) and Angular 2 special selectors specifically. My question is two-fold:
The Angular CLI can help you stylev12 introduced the option to use inline Sass in your Angular components. The CLI now has an option to provide a inlineStyleLanguage and compiles Sass directly from your Angular components into styling.
::ng-deep , /deep/ and >>> deprecation The ::ng-deep pseudo-class selector also has a couple of aliases: >>> and /deep/ , and all three are soon to be removed. The main reason for that is that this mechanism for piercing the style isolation sandbox around a component can potentially encourage bad styling practices.
The :has() pseudo-class takes a selector list as an argument. In the current specification :has is not marked as part of the live selector profile, which means it can not be used within stylesheets; only with functions like document. querySelector().
::ng-deep is what's called a shadow-piercing descendant combinator. It works because it is able to pierce the shadow DOM. Using ::ng-deep to override a child components styles will achieve the desired result but with unintended side effects.
Replacing :host
with \:host
and >>>
with /deep/
worked for me.
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