Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Style ng-bootstrap - Alternative to /deep/

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?

like image 553
Felipe Avatar asked Aug 01 '17 18:08

Felipe


People also ask

Is it possible to style ng-bootstrap tooltips inside the tooltip?

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; }

How to implement ngstyle in angular?

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:

What is the best alternative to bootstrap?

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.

How do styles propagate from parent to child components in angular?

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


Video Answer


2 Answers

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

like image 78
DeborahK Avatar answered Oct 22 '22 07:10

DeborahK


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.

like image 43
Felipe Avatar answered Oct 22 '22 09:10

Felipe