I am using the accordion
component from ng-bootstrap in one of my apps and the /deep/
(aka: ::ng-deep
and >>>
) selector to set its styles. However I saw this selector has been deprecated.
Is there an alternative to set the styles of the ng-bootstrap components?
I confirmed the tooltip-inner class is used inside the tooltip but it's not being applied This Plunker shows how you can style ng-bootstrap tooltips. The key is to use /deep/ or ::ng-deep ** to force the style into the child component: ::ng-deep .tooltip-inner { background-color: #00acd6; color: #fff; }
If we run into such an use case using Angular, we can implement it using the ngStyle built-in core directive: Just like the case of ngClass, if our ngStyle expression starts to get too large, we can always call a component method to calculate the configuration object:
Foundation by Zurb " A Framework for any device, medium, and accessibility." is what they call themselves and they certainly are true. With all the perks of an advanced framework, Foundation is definitely the strongest alternative to Bootstrap.
By default, Angular uses Emulated view encapsulation which means styles will not propagate from a parent to a child component unless you tell them to (e.g. using ::ng-deep ). ** /deep/ was deprecated in Angular 4.3.0 and ::ng-deep is now preferred, although according to the link this will also be deprecated in the future
Support for the emulated /deep/ CSS Selector (the Shadow-Piercing descendant combinator aka >>>) has been deprecated to match browser implementations and Chrome’s intent to remove. ::ng-deep has been added to provide a temporary workaround for developers currently using this feature.
From here: http://angularjs.blogspot.com/2017/07/angular-43-now-available.html
I've done some digging and it is possible to overwrite the ng-bootstrap styles if you turn off the view encapsulation for a component, like so:
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class ExampleComponent {
constructor(public activeModal: NgbActiveModal) { }
}
For example, here I am customizing the styles for a modal dialog, because I assumed that my example component should be shown as a modal dialog and I want its width to be at maximum 70% of the view port in small screen sizes:
.modal-dialog {
@include media-breakpoint-down(xs) {
max-width: 70vw;
margin: 10px auto;
}
}
Please note that turning off the view encapsulation means that the styles for this particular component will be available throughout the application, therefore other components will have access to them and will eventually use them if you are not careful.
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