Namespace Mixins (#gradient > .horizontal) from twitter Bootstrap preboot not compiled
Hi there,
I'm using twitters Bootstrap (http://twitter.github.com/bootstrap/) and everything seems to work fine. Just the parametric mixins #font and #gradient won't work. They are included in the preboot.less file and look like that (shortend version):
#font {
.shorthand(@weight: normal, @size: 14px, @lineHeight: 20px) {
font-size: @size;
font-weight: @weight;
line-height: @lineHeight;
}
.sans-serif(@weight: normal, @size: 14px, @lineHeight: 20px) {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: @size;
font-weight: @weight;
line-height: @lineHeight;
}
}
#gradient {
.horizontal (@startColor: #555, @endColor: #333) {
background-color: @endColor;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, right top, from(@startColor), to(@endColor)); // Konqueror
background-image: -moz-linear-gradient(left, @startColor, @endColor); // FF 3.6+
background-image: -ms-linear-gradient(left, @startColor, @endColor); // IE10
background-image: -webkit-gradient(linear, left top, right top, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+
background-image: -webkit-linear-gradient(left, @startColor, @endColor); // Safari 5.1+, Chrome 10+
background-image: -o-linear-gradient(left, @startColor, @endColor); // Opera 11.10
background-image: linear-gradient(left, @startColor, @endColor); // Le standard
}
.vertical (@startColor: #555, @endColor: #333) {
background-color: @endColor;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(@startColor), to(@endColor)); // Konqueror
background-image: -moz-linear-gradient(@startColor, @endColor); // FF 3.6+
background-image: -ms-linear-gradient(@startColor, @endColor); // IE10
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @startColor), color-stop(100%, @endColor)); // Safari 4+, Chrome 2+
background-image: -webkit-linear-gradient(@startColor, @endColor); // Safari 5.1+, Chrome 10+
background-image: -o-linear-gradient(@startColor, @endColor); // Opera 11.10
background-image: linear-gradient(@startColor, @endColor); // The standard
}
}
There are no errors when compiling but the rules are included in the stylesheet like that:
#font .shorthand(@weight: normal, #font $size: 14px, #font $lineHeight: 20px) {
font-size:;
font-weight:;
line-height:;
}
but not when I'm using them like that:
#gradient > .vertical(lighten(@blue, 20%), @blue);
#font > .shorthand(bold, 15px, 1.2);
I don't understand why though since this works on your example page (http://leafo.net/lessphp/#demo):
#bundle {
.button (@color: #000) {
border: 1px solid @color;
background-color: grey;
}
}
#header a {
color: orange;
#bundle > .button(#ccc);
}
change #gradient to @gradient and the commas between parameters to semicolon. It works fine.
Thank you very much! I'll try that!
Maybe it would still be good to "fix" this so you can use your less files without having to change parts of a framework like Bootstrap.
OK, much better. However it still doesn't work perfectly. Button gradients are just left out and so buttons are just gray.
And - if I change the syntax as you suggested, I get syntax errors when using less.js
The lessjs syntax and lessphp syntax is different. Go with one! I changed Bootstrap to work with lessphp and it successfully compiled. The compile result is the same file as bootstrap-1.3.0-min.css. You just have to change the syntax to be compatible with lessphp. (or change nothing and use less.js)
I'm having the same problem. I have a variables file defined that contains font stacks:
@serif: "Cambria", Georgia, serif;
@sans: Helvetica, Arial, sans-serif;
@font {
.h1(@lineHeight: 36px) {
font-family: @sans;
font-size: 33px;
font-weight: normal;
line-height: @lineHeight;
}
.h2(@stack: @sans; @color: @fidelityGreen; @lineHeight: 27px) {
color: @color;
font-family: @stack;
font-size: 24px;
font-weight: bold;
line-height: @lineHeight;
}
.small(@stack: @serif; @weight: normal; @transform: none; @lineHeight: 15px) {
font-family: @stack;
font-size: 12px;
font-weight: @weight;
line-height: @lineHeight;
text-transform: @transform;
}
}
...etc. However, they're ignored by the compiler when used like this:
@font > .small();
With commas separating values, it ignores them. With semicolons (as above) it throws a fatal error:
lessc fatal error:
parse error: failed at `.h2(@stack: @sans; @color: @fidelityGreen; @lineHeight: 27px) {` css/lib/variables.less on line 88
Using lessphp v0.3.0
What am I doing wrong?
It compiled fine using v0.2.1. I don't know about 0.3.0 but 0.2 is the stable version, use that instead.
shazdeh:
I changed Bootstrap to work with lessphp and it successfully compiled. The compile result is the same file as bootstrap-1.3.0-min.css. You just have to change the syntax to be compatible with lessphp. (or change nothing and use less.js)
Could you share the compatible bootstrap less files? Or what exactly syntax should be changed? I'm using twitter-bootstrap-v1.4.0 and it's already using semicolons.
I have a problem with clearfix. This less code from bootstrap:
.clearfix() {
zoom: 1;
&:before,
&:after {
display: table;
content: "";
zoom: 1;
}
&:after {
clear: both;
}
.fixed-container() {
width: @siteWidth;
margin-left: auto;
margin-right: auto;
.clearfix();
}
}
.container {
.fixed-container();
}
Should create:
.container:after {
clear: both;
}
.container:before, .container:after {
content: "";
display: table;
}
.container:before, .container:after {
content: "";
display: table;
}
.container {
margin-left: auto;
margin-right: auto;
width: 940px;
}
But it's actually create only this:
.container {
margin-left: auto;
margin-right: auto;
width: 940px;
}
Looks like the problem with something else... :( If I remove all other code from bootstrap less files it works fine
F**k - Took me 1 hour to find a problem: Removed this code from variables.less and it started parsing fine
// More variables coming soon:
// - @basefont to @baseFontSize
// - @baseline to @baseLineHeight
// - @baseFontFamily
// - @primaryButtonColor
// - anything else? File an issue on GitHub
Just in case, here I keep a repo of a lessphp compatible bootstrap styles: https://github.com/shazdeh/Bootstrap-for-LESSPHP. (It's still 1.3.0 but I'll update it)
Sorry for the long delay on getting this to work. I just pushed 0.3.0 to master. It works with twitter bootstrap now. I changed lessphp syntax to match that of lessjs.
I enhanced the lessphp documentation a bunch too, check it out: http://leafo.net/lessphp/docs/
Following the mixins notation documented in the new Twitter Bootstrap 2, I fail at making it working with lessphp 0.3.2.
Following the previous examples, I tried the followings in my code:
background: @translucent .background(#221504, 0.97);
background: @translucent > .background(#221504, 0.97);
background: #translucent .background(#221504, 0.97);
background: #translucent > .background(#221504, 0.97);
background: .#translucent .background(#221504, 0.97);
background: .#translucent > .background(#221504, 0.97);
Any hint?
Remove the "background:" in your CSS. This is working for me: body { #translucent > .background(#221504, .5); }
Shame on me, you're totally right @shazdeh ! Thanks :-)
I am using v0.3.4-2 and I am still having this problem.
#translucent > .background( [anything], [anything] );
Doesn't work. It's replaced with nothing.
Can't reproduce this @aaronldunlap Going to close this issue because it's unrelated. Open an new one if you are still having trouble.