Skip to content

Instantly share code, notes, and snippets.

@swistak
Created April 20, 2012 21:12
Show Gist options
  • Save swistak/2431943 to your computer and use it in GitHub Desktop.
Save swistak/2431943 to your computer and use it in GitHub Desktop.
How to make a semantic classes with twitter grid functionality.
// Example usage
.row {
#fixed .row()
}
.row-fluid {
#fluid .row()
}
.main {
#fixed .span(8);
}
.sidebar {
#fixed .span(4)
}
// A semantic cersion of bootstrap grid system.
// Usage:
//
// Replace `@import "grid.less";` with `@import "semantic_grid.less";`
//
// WARNING: With this you won't be able to use a responsive grid.
// Unless you add .row .row-fluid and .span classes to every element including responsive mixin.
//
// Reason for this are catch-all overrides using [class*=span] in responsive.less
// Core variables and mixins
@import "./twitter/bootstrap/variables.less"; // Modify this for custom colors, font-sizes, etc
@import "./twitter/bootstrap/mixins.less";
#fluid {
.span (@columns) {
width: (@fluidGridColumnWidth * @columns) + (@fluidGridGutterWidth * (@columns - 1));
float: left;
margin-left: @fluidGridGutterWidth;
&:first-child {
margin-left: 0;
}
}
.row() {
width: 100%;
.clearfix();
}
}
#fixed {
.offset (@columns) {
margin-left: (@gridColumnWidth * @columns) + (@gridGutterWidth * (@columns - 1)) + (@gridGutterWidth * 2);
}
.spanWidth(@columns) {
width: (@gridColumnWidth * @columns) + (@gridGutterWidth * (@columns - 1));
}
.span (@columns) {
.spanWidth(@columns);
float: left;
margin-left: @gridGutterWidth;
}
.row() {
margin-left: @gridGutterWidth * -1;
.clearfix();
}
}
#input {
.span(@columns) {
width: ((@gridColumnWidth) * @columns) + (@gridGutterWidth * (@columns - 1)) - 10;
}
}
.container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container { #fixed .spanWidth(@gridColumns); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment