Skip to content

Instantly share code, notes, and snippets.

@sergej-brazdeikis
Created July 14, 2012 09:25
Show Gist options
  • Save sergej-brazdeikis/3110172 to your computer and use it in GitHub Desktop.
Save sergej-brazdeikis/3110172 to your computer and use it in GitHub Desktop.
grid 960 using less.js
/*
rewriten to less.js by Sergej Jevsejev
@date 2012 07 14
@webpage http://sjevsejev.blogspot.com
960 Grid System ~ Core CSS.
Learn more ~ http://960.gs/
Licensed under GPL and MIT.
*/
/*
Forces backgrounds to span full width,
even if there is horizontal scrolling.
Increase this if your layout is wider.
Note: IE6 works fine without this fix.
*/
// settings
@columns: 16;
@bodyWidth: 960px;
@columnMargin: 10px;
// vars
@columnWidth: ( @bodyWidth - @columns * @columnMargin * 2 ) / @columns;
body {
min-width: @bodyWidth;
}
//Container
(~".container_@{columns}") {
margin-right: auto;
margin-left: auto;
width: @bodyWidth;
}
.gridGlobal (@index) when (@index > 0) {
(~".grid_@{index}") {
display: inline;
float: right;
margin-right: @columnMargin;
margin-left: @columnMargin;
}
.gridGlobal(@index - 1);
}
.gridGlobal (0) {}
.gridGlobal (@columns);
.pushPull (@index) when (@index > 0) {
(~".push_@{index}, .pull_@{index}") {
position: relative;
}
@width: @bodyWidth - (@columns - @index) * (@columnWidth + @columnMargin * 2);
// Prefix Extra Space >> Columns
(~".container_@{columns}, .prefix_@{index}") {
padding-right: @width;
}
// Suffix Extra Space >> Columns
(~".container_@{columns}, .suffix_@{index}") {
padding-left: @width;
}
// Push Space >> Columns
(~".container_@{columns}, .push_@{index}") {
right: @width;
}
// Pull Space >> Columns
(~".container_@{columns}, .pull_@{index}") {
right: -@width;
}
.pushPull(@index - 1);
}
.pushPull (0) {}
.pushPull (@columns - 1);
// Grid >> Children (Alpha ~ First, Omega ~ Last)
.alpha { margin-right: 0; }
.omega { margin-left: 0; }
.gridColumns (@index) when (@index > 0) {
// Grid >> Columns
(~".container_@{columns} .grid_@{index}") {
width: @bodyWidth - 2*@columnMargin - (@columns - @index) * (@columnWidth + 2*@columnMargin);
}
.gridColumns(@index - 1);
}
.gridColumns (0) {}
.gridColumns (@columns);
/* `Clear Floated Elements
----------------------------------------------------------------------------------------------------*/
/* http://sonspring.com/journal/clearing-floats */
.clear {
clear: both;
display: block;
overflow: hidden;
visibility: hidden;
width: 0;
height: 0;
}
/* http://www.yuiblog.com/blog/2010/09/27/clearfix-reloaded-overflowhidden-demystified */
.clearfix:before,
.clearfix:after,
(~".container_@{columns}:before"),
(~".container_@{columns}:after") {
content: '.';
display: block;
overflow: hidden;
visibility: hidden;
font-size: 0;
line-height: 0;
width: 0;
height: 0;
}
.clearfix:after,
(~".container_@{columns}:after"){
clear: both;
}
/*
The following zoom:1 rule is specifically for IE6 + IE7.
Move to separate stylesheet if invalid CSS is a problem.
*/
.clearfix,
(~".container_@{columns}") {
zoom: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment