【问题标题】:How to get direction(rtl/ltr) without know who has dir attribute?如何在不知道谁具有 dir 属性的情况下获取方向(rtl/ltr)?
【发布时间】:2019-04-05 15:52:40
【问题描述】:

我不会根据父方向创建具有不同样式的组件。

例如:

<!-- some tags with dir attribute -->
<my-component></my-component>
<!--close some tags with dir attribute -->

相当于:dir(ltr) 的东西有 chrome 支持?

更新: 这是工作,但我怎样才能在另一种风格中使用它?

[dir='rtl']  mat-header-cell {
  border-left: dashed;
}
[dir='ltr']  mat-header-cell {
  border-right: dashed;
} 

【问题讨论】:

  • 你能分享你的完整代码吗?谢谢

标签: javascript css angular


【解决方案1】:

如果您尝试从组件中调整:host-context 选择器,则可以使用它:

@Component({
  template: `
    <div class="with-border">Lorem</div>
  `,
  selector: 'my-component',
  styles: [`
    :host-context([dir='rtl']) .with-border {
      border-left: dashed;
    }
    :host-context([dir='rtl']) .with-border {
      border-right: dashed;
    }
  `]
})
export class MyComponent {}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 2012-10-16
    • 2017-05-01
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多