Your Issue in Detail
As seven-phases-max described, there are issues with name spacing "when the &
is appended to a nested selector." So the Bootstrap code in part has this:
.caret {
.btn-default & {
border-top-color: @btn-default-color;
}
.btn-primary &,
.btn-success &,
.btn-warning &,
.btn-danger &,
.btn-info & {
border-top-color: #fff;
}
}
Recall that every instance of &
is replaced with the full nesting structure, so when you namespace it as you are, you effectively have this:
.namespace-bs {
.caret {
.btn-default & {
border-top-color: @btn-default-color;
}
.btn-primary &,
.btn-success &,
.btn-warning &,
.btn-danger &,
.btn-info & {
border-top-color: #fff;
}
}
}
And the full nested structure is .namespace .caret
at the point of the &
replacement, which is why you are seeing the selectors look like .btn-primary .namespace-bs .caret
etc.
Work Around for LESS 1.4+
The following should work:
Compile bootstrap from its LESS code as normal into a bootstrap.css
file. This will resolve all LESS into the "normal" bootstrap css code, and the &
will function as expected and desired wherever it is used.
Then in your name spacing LESS file, do this:
.namespace-bs {
@import (less) "css/bootstrap.css";
}
What we are doing is importing the compiled bootstrap.css
file (which has no more &
values in it, as it is fully compiled), but as we import it, we are telling LESS to treat the CSS as LESS code by putting the (less)
type casting in. So now, your name space should simply append itself to the full selector string of each selector in the bootstrap.css
file, and you should end up with what you desire.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…