Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LTR and RTL in IONIC 4

Tags:

angular

I am using ngx-translate in ionic 4 to add different languages. In my project I have arabic language. ngx-translate functionality is working fine. It is changing dir for html tag dynamically.

Problem: I want to write some styles if html tag has dir="rtl" in each component. But angular has default encapsulation, So I am unable to write the styles as follows in my component.scss file.

html[dir="rtl"]{
  h3{
     color: red;
  }
}

I know that angular provides encapsulation change properties like,

encapsulation: ViewEncapsulation.None

But I don't want to use the advantage of encapsulation.

Thanks for the help.

like image 563
Anji Avatar asked Sep 20 '18 12:09

Anji


1 Answers

Sometimes it's useful to apply styles based on some condition outside of a component's view. For example, a CSS theme class could be applied to the document <body> element, and you want to change how your component looks based on that.

:host-context Full Documentation

Use the :host-context() pseudo-class selector, which works just like the function form of :host(). The :host-context() selector looks for a CSS class in any ancestor of the component host element, up to the document root. The :host-context() selector is useful when combined with another selector.

:host-context(html[dir="rtl"]) ion-card-subtitle {
  background-color: #eef;
}
like image 128
Navid Kianfar Avatar answered Sep 28 '22 15:09

Navid Kianfar