是否可以在LESS中添加父选择器? [英] Is it possible to add a parent selector in LESS?
本文介绍了是否可以在LESS中添加父选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的CSS是由组件构成的,每个组件都是独立的.
My css is structured in components, each component is stand-alone.
示例:
.menu {
background: black;
}
我正在使用的框架有时会在body-tag中添加一个类.例如,对于已登录的用户,它看起来像这样:
The framework I'm using sometimes adds a class to the body-tag. For example for logged in users it would look like this:
<body class="loggedIn">
<div class="menu"</div>
</body
我想在每个组件中保持css的结构化.是否可以在父级之前添加的选择器中添加较少的选择器?像这样:
I would like to keep the css structured inside each component. Is it possible to add a selector in less that is added before the parent? Something like:
.menu{
%loggedIn{
color: red
}
}
应该为已登录的用户提供一个红色菜单.
should give loggedIn users a red menu.
推荐答案
除非我完全对你有误解,并且有可能,那么&父母选择符正是你所需要的!
Unless I am completely missunderstanding you, and there is a possibility, then the ampersand-parent-selector is exactly what you need!
.menu{
.loggedIn & {
color: red
}
}
应该导致
.loggedIn .menu {
color: red
}
这篇关于是否可以在LESS中添加父选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文