Html 检查父级是ltr还是rtl

Html 检查父级是ltr还是rtl,html,css,Html,Css,是否可以检查父元素的css是ltr还是rtl,然后对子元素应用不同的样式 例如,我有: <div class="parent ltr"><div class="child"></div></div> 及 我想根据父div的ltr或rtl为子类设置不同的样式。根据您的代码确定: .ltr .child { /* some styles here */} .rtl .child { /* other styles here */} div.

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

例如,我有:

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



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

根据您的代码确定:

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

根据您的代码确定:

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

您只需根据您的孩子是在
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 }

您只需根据您的孩子是在
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 }