Skip to content

Instantly share code, notes, and snippets.

@ilearnio
Created December 14, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilearnio/b71952958175b831e161b7c79fe9c180 to your computer and use it in GitHub Desktop.
Save ilearnio/b71952958175b831e161b7c79fe9c180 to your computer and use it in GitHub Desktop.
CSS grid generator. Based on https://www.sitepoint.com/understanding-css-grid-systems/ formula
var mc = 12 // maximum columns
var m = 2 // margin in %
var scw = (100 - (m * (mc - 1))) / mc
var str = `
.row,
.column {
box-sizing: border-box;
}
.row:before,
.row:after {
content: " ";
display: table;
}
.row:after {
clear: both;
}
.column {
position: relative;
float: left;
}
.column + .column {
margin-left: ${m}%;
}
`
for (var i = 0; i < mc; i++) {
let cw = (scw * (i + 1)) + (m * ((i + 1) - 1))
str += '.column-' + (i + 1) + ' {\n width: ' + (cw.toFixed(6) - 0) + '%;\n}\n\n'
}
str += `
@media only screen and (max-width: 550px) {
.column {
width: auto;
float: none;
}
.column + .column {
margin-left: 0;
}
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment