命名空间和访问器
(不要与 CSS @namespace
或 命名空间选择器 混淆)。
有时,出于组织目的或只是为了提供一些封装,你可能希望对混入进行分组。 你可以在 Less 中非常直观地做到这一点。 假设你想在 #bundle
下打包一些混入和变量,以供以后重用或分发:
#bundle() {
.button {
display: block;
border: 1px solid black;
background-color: grey;
&:hover {
background-color: white;
}
}
.tab { ... }
.citation { ... }
}
现在如果我们想在我们的 #header a
中混合 .button
类,我们可以这样做:
#header a {
color: orange;
#bundle.button(); // can also be written as #bundle > .button
}
注意: 如果你不希望它出现在你的 CSS 输出中(即 #bundle .tab
),请将 ()
附加到你的命名空间(例如 #bundle()
)。