问题
I have the following stack:
- Symfony2
- Twig with lessphp filter installed.
- Twitter Boostrap
In base.css i have:
// base.less
@import '/path/to/bootstrap.less'
@linkColor: 13px;
Variable name is not important at all. It can be any other variable used in bootstrap. It just doesn't get overridden. But if i put the variable into separate .less file and import it in base.less everything works as expected:
// base.less
@import '/path/to/bootstrap.less'
@import '/path/to/variables.less'
and
// variables.less
@linkColor: 13px;
Why does this work and the other not? Looked up for the docs (less/lessphp) but couldn't find anything related to this. (or i didn't know where to look).
Can someone explain why is this happening?
回答1:
It looks like it's a bug in the lessphp compiler. Take a look at the github issue. Your workaround, to put the variable declaration into another file and also import it works just fine. Thanks by the way ;)
回答2:
This is happening because you override the variable after it's been used to define all the Bootstrap styles.
I solve this problem this way:
- Create my own
main.less
that imports my ownbootstrap.less
. - My own
bootstrap.less
is just the Bootstrap'sbootstrap.less
file copied over to my own folder with import paths changed accordingly, but with one exception: it imports by ownvariables.less
instead of the Bootstrap's one. - My own
variables.less
imports the Bootstrap'svariables.less
and then overrides the ones I need.
来源:https://stackoverflow.com/questions/15426256/override-less-variables