-
-
Save barryvdh/2834636 to your computer and use it in GitHub Desktop.
/* ===== Primary Styles ===================================================== | |
Author: Fruitcake Studio (Barry vd. Heuvel) | |
========================================================================== */ | |
//Generate a custom (semantic) grid | |
.customGrid(@gridColumnWidth, @gridGutterWidth){ | |
#header, #main { | |
.row(); | |
} | |
.block { | |
.span(3); | |
} | |
#content{ | |
.span(9); | |
} | |
footer { | |
#copyright { | |
.span(12); | |
} | |
} | |
.thumbnails > li { | |
.span(3); | |
} | |
/* ===== Custom grid mixins ================================================= | |
Do not change this mixin below this line! | |
========================================================================== */ | |
.row() when( isnumber(@gridColumnWidth) ) { | |
margin-left: @gridGutterWidth * -1; | |
.clearfix(); | |
} | |
.row() when(@gridColumnWidth = auto){ | |
margin-left: 0; | |
} | |
.span(@columns: 1, @offset: 0) when( isnumber(@gridColumnWidth) ) { | |
float: left; | |
margin-left: (@gridColumnWidth * @offset) + (@gridGutterWidth * (@offset - 1)) + (@gridGutterWidth * 2); | |
width: (@gridColumnWidth * @columns) + (@gridGutterWidth * (@columns - 1)); | |
min-height: 1px; // prevent collapsing columns | |
} | |
.span (@columns, @offset: 0) when(@gridColumnWidth = auto){ | |
float: none; | |
display: block; | |
width: 100%; | |
margin-left: 0; | |
.box-sizing(border-box); | |
} | |
} | |
// Custom grid (default size) | |
.customGrid(@gridColumnWidth, @gridGutterWidth); |
Thanks for sharing. Unfortunately I have encountered some problems using the prescribed method.
I see the same span width calculation errors as mentioned here by @ashtewari. Ash has kindly created and shared his example files, you can see the error on his test site too (http://ash.site44.com/hero.html).
The other problem I have is, while this appears to sort-of work using less.js, I can't get this to compile at all using my preprocessor (CodeKit for Mac OS X), I see the following error:
No matching definition was found for .row()
Here's hoping that a real solution will eventually be integrated into the Boostrap core.
I only tested this on lessPHP, an PHP port of Less.JS, which tries to do behave the same as Less.js
In my testcase, the result of .span4 , is the same as a .block with .span(4).
I have edited my gists to reflect changes in Bootstrap 2.3, but that doesn't change the width calculations.
@ashtewari and @adrianoldham, I changed some of the code and tested it with the latest Bootstrap version (2.3) and in both lessphp and less.js. It seems to be working fine now.
less.js seemed to deal differently with the scope variables, and also didn't like isNumber (should be isnumber).
Also tried to make it a bit simpler (just a mixin .customGrid instead #custom .grid()). Does this work better for you?
Thanks for sharing this code!
I've imported in the order prescribed, and things work fine till I run into an issue in the custom-responsive.less …
These two lines throw an error, and return as undefined variables.
Is there a piece I'm missing where you define them elsewhere in your code? I can see the rest is working, as I'm able to get the media queries for this view:
@media (max-width: 767px) {
.customGrid(auto, 0);
}
Much appreciate your help!
LB
Left out the two troublesome lines… sorry about that:
.customGrid(@gridColumnWidth768, @gridGutterWidth768);
and
.customGrid(@gridColumnWidth1200, @gridGutterWidth1200);
I see. It makes sense now. The grid is responsive now. The span(4) width is not the same as the original (non-semantic) version, but I will play around with this to see what might be missing.
Thanks for taking the time to explain this.