仅当元素具有某个子元素时,才向元素添加规则 [英] add a rule to an element only if it has a certain child

查看:168
本文介绍了仅当元素具有某个子元素时,才向元素添加规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法,只有当它有一个特定的子元素时,添加CSS规则到元素?我知道这是不可能用CSS做,但我不知道是否可以用LESS做。

Is there a way of adding CSS rules to an element only if it has an certain child element ? I do know it is not possible to do it with CSS, but I'm not sure if it is possible to do it with LESS.

推荐答案

如果不可能使用CSS,那么它不可能与LESS一起编译为纯旧的vanilla CSS。

If it is not possible with CSS, then it is not possible with LESS, which compiles to plain old vanilla CSS.

问题是,LESS是在没有应用于其的HTML的知识的情况下编译的,并且没有任何客户端脚本。因此,不可能实现用单独使用CSS无法实现的LESS。

The problem is, that the LESS is compiled without knowledge of the HTML it is applied to, and without any client side scripting. Therefore, it is impossible to achieve anything with LESS that can not be achieved by using CSS alone.

您可以使用客户端JavaScript实现您想要的,或者您可以等待,直到CSS4出来,并使用父选择器的效果与你想要的相同。

You could achieve what you want by using client side javascript, or you could wait until CSS4 comes out, and use the parent selectors to the same effect as what you want.

这篇关于仅当元素具有某个子元素时,才向元素添加规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆