Less 多胎直系子女减少
预期CSS:Less 多胎直系子女减少,less,siblings,Less,Siblings,预期CSS: .parent > .type1 { color: red; } .parent > .type2 { color: red; } .parent > .type3 { color: red; } 原件减去: .parent { & > .type1, & > .type2, & > .type3 { color: red; } } 如何组合type1/type2
.parent > .type1 {
color: red;
}
.parent > .type2 {
color: red;
}
.parent > .type3 {
color: red;
}
原件减去:
.parent {
& > .type1, & > .type2, & > .type3 {
color: red;
}
}
如何组合type1/type2/type3?
这不起作用,因为type2/type3将编译为后代,而不是直接子代:
.parent {
& > .type1, .type2, .type3 {
color: red;
}
}
使用更少的代码,
和
将替换为整个包装选择器
这意味着
.parent {
& > .type1, .type2, .type3 {...}
}
变成
.parent > .type1, .type2, .type3 {...}
为了使代码更简洁,您应该注意,
组合器不是可选的,但是&
变得多余。编写此选择器的适当方法是:
.parent {
> .type1,
> .type2,
> .type3 {...}
}
这反过来会产生
.parent > .type1,
.parent > .type2,
.parent > .type3 {...}
使用更少的代码,
和
将替换为整个包装选择器
这意味着
.parent {
& > .type1, .type2, .type3 {...}
}
变成
.parent > .type1, .type2, .type3 {...}
为了使代码更简洁,您应该注意,
组合器不是可选的,但是&
变得多余。编写此选择器的适当方法是:
.parent {
> .type1,
> .type2,
> .type3 {...}
}
这反过来会产生
.parent > .type1,
.parent > .type2,
.parent > .type3 {...}
嗯,有点不清楚(你所说的“组合”是什么意思),请指定你实际期望得到的CSS。仅供参考
既不表示兄弟姐妹也不表示相邻兄弟姐妹:)嗯,有点不清楚(你所说的“组合”是什么意思),请指定您实际希望获得的CSS。仅供参考
既不表示兄弟姐妹,也不表示相邻兄弟姐妹:)