检查父项是ltr还是rtl

时间:2013-09-09 14:31:27

标签: html css

是否可以检查父级的css是ltr还是rtl,然后对子元素应用不同的样式?

例如我有:

<div class="parent ltr"><div class="child"></div></div>

<div class="parent rtl"><div class="child"></div></div>

我想基于父div的ltr或rtl为子类设置不同的样式。

3 个答案:

答案 0 :(得分:2)

您可以根据您的孩子是在rtl还是ltr父母内部来指定不同的样式:

.ltr .child { ... details of child of ltr }
.rtl .child { ... details of child of rtl }

或者您可以在CSS中使用“直接后代”来进行更严格的控制:

.ltr > .child { ... details of child of ltr }
.rtl > .child { ... details of child of rtl }

答案 1 :(得分:1)

.ltr .child { /* some styles here */}
.rtl .child { /* other styles here */}

答案 2 :(得分:0)

根据您的代码确定:

div.parent.ltr div.child { /* one set of rules */ }
div.parent.rtl div.child { /* a different set of rules */ }