html - 如何使用 LESS 从深度嵌套的 HTML 元素中定位父 HTML 元素?
问题描述
是否可以在 LESS 文件中定位外部(“great-grand-”)“父”HTML 元素,其中元素可互换地div
嵌套在元素内部?span
例如:
<div class="parent1 class1 class2">Parent shape
<span class="parent2">
<div class="parent3">
<div class="parent4 some-other-class">
Some content....
</div>
</div>
</span>
</div>
我想要实现的是在嵌套最深的元素应用了这些类“ ”时,为div
具有“”类的 FIRST 元素应用样式。.parent1 class1 class2
div
.parent4 some-other-class
重要笔记:
- 默认情况下,最深层嵌套
div
的元素只.parent4
应用了类 - 样式应应用于应用了以下类的顶级父
div
元素parent1 class1 class2
- TOP-PARENT
div
元素的样式应该在且仅some-other-class
当类被附加到嵌套最深的 DIV 时应用(即当它是 时<div class="parent4 some-other-class">
)
这是我现在的.less
文件:
.parent1{
&.class1.class2{
div.parent.some-other-class & div.parent3 & span.parent2 {
//css styling applied for `div.parent1.class1.class2`
}
}
}
...但它不工作。顺便说一句,所有选择器都必须.parent1
在 LESS 文件中的类内 -> 这意味着 .less 文件必须是这样的:
.parent1{
// ALL other selectors (e.g. `.parent2` , `.parent4.some-other-class` ) are inside of this block!
}
...而不是这样:
.parent1{
/* styling */
}
.parent4.some-other-class{
/* styling */
}
这是与此问题相关的最相似的问答,但它适用于存在单亲和单子元素的最微不足道的情况。
非常感谢任何帮助/建议。
解决方案
推荐阅读
- javascript - 隐藏逗号到空格
- python - 如何找出`DataFrame.to_numpy`没有创建副本
- jquery-select2 - Select2 下拉菜单显示
- ios - SceneKit 头发骨骼动态运动限制,头发动画
- javascript - Invariant Violation: App (...):Nothing 从 render 返回。这通常意味着缺少 return 语句。或者,不渲染任何东西,返回 null
- python - 在我运行此消息后弹出 ValueError: invalid literal for int() with base 10: ''
- javascript - 这是我的键码输入代码,但什么也没发生 - 纯 Javascript 而不是 jquery
- python - 无法从 Kivy 中的 DropDown 小部件中获取正确的项目选择
- mysql - 计算平均值、添加日期并将查询保存到新表
- php - 如何在 php 中以逗号分隔的形式返回数组值?