Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@r3wt
Last active January 5, 2017 01:22
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 r3wt/3bf8d6aa2c7a5217658dff4e53ec9c84 to your computer and use it in GitHub Desktop.
Save r3wt/3bf8d6aa2c7a5217658dff4e53ec9c84 to your computer and use it in GitHub Desktop.
ez tiny grid framework. no jquery!

No media queries are used Since tablets and mobiles are now displaying huge resolutions, if we think its mobile, the body gets a class of .m, if we think its a tablet, it gets a class of .t. if its neither mobile nor tablet,it gets .d unless the screen is wider than 1920px, then it gets .hd

  • Columns must use class .col
  • Mobile use class .m-{desired size} eg .m-12
  • Tablet use class .t-{desired size} eg .t-6
  • Desktop use class .d-{desired size} eg .d-4
  • Huge Desktop use class .hd-{desired size} eg .hd-2
  • 12 columns (.col). extras .row, .container, .container.fluid
  • use .{size}-hide to hide eg .m-hide would hide for mobile.

eg: .col.m-12.t-6.d-4.hd-2 would be 100% width on mobile, 50% width tablet, 33.3% width desktop, 16.6% width huge desktop.

examples:

<div class="col m-12 t-6 d-4 hd-hide">
I'm responsive, but hidden on huge desktops (screens > 1920px)
</div>

<div class="row">
  <div class="container">
    My max width is 1200px
  </div>
</div>
<div class="col m-hide">
I'm hidden on mobile.
</div>
!function(w,d){
function mC() {
var c = 0;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) c = 1;})(navigator.userAgent||navigator.vendor||window.opera);
return c;
}
var b = d.body;
function style(){
var s = d.createElement('style');
s.innerHTML = ".col,.container{width:100%;padding:0 12px}body{opacity:0}*{box-sizing:border-box}.container{max-width:1200px;margin:0 auto}.container.fluid,body.m .container{max-width:none}.row:after,.row:before{content:' ';display:table;clear:both}body.d .col.d-hide,body.hd .col.hd-hide,body.m .col.m-hide,body.t .col.t-hide{display:none!important}.col{float:left;min-height:1px}body.m .col.m-1{width:8.33333%}body.m .col.m-offset-1{margin-left:8.33333%}body.m .col.m-2{width:16.66667%}body.m .col.m-offset-2{margin-left:16.66667%}body.m .col.m-3{width:25%}body.m .col.m-offset-3{margin-left:25%}body.m .col.m-4{width:33.33333%}body.m .col.m-offset-4{margin-left:33.33333%}body.m .col.m-5{width:41.66667%}body.m .col.m-offset-5{margin-left:41.66667%}body.m .col.m-6{width:50%}body.m .col.m-offset-6{margin-left:50%}body.m .col.m-7{width:58.33333%}body.m .col.m-offset-7{margin-left:58.33333%}body.m .col.m-8{width:66.66667%}body.m .col.m-offset-8{margin-left:66.66667%}body.m .col.m-9{width:75%}body.m .col.m-offset-9{margin-left:75%}body.m .col.m-10{width:83.33333%}body.m .col.m-offset-10{margin-left:83.33333%}body.m .col.m-11{width:91.66667%}body.m .col.m-offset-11{margin-left:91.66667%}body.m .col.m-12{width:100%}body.t .col.t-1{width:8.33333%}body.t .col.t-offset-1{margin-left:8.33333%}body.t .col.t-2{width:16.66667%}body.t .col.t-offset-2{margin-left:16.66667%}body.t .col.t-3{width:25%}body.t .col.t-offset-3{margin-left:25%}body.t .col.t-4{width:33.33333%}body.t .col.t-offset-4{margin-left:33.33333%}body.t .col.t-5{width:41.66667%}body.t .col.t-offset-5{margin-left:41.66667%}body.t .col.t-6{width:50%}body.t .col.t-offset-6{margin-left:50%}body.t .col.t-7{width:58.33333%}body.t .col.t-offset-7{margin-left:58.33333%}body.t .col.t-8{width:66.66667%}body.t .col.t-offset-8{margin-left:66.66667%}body.t .col.t-9{width:75%}body.t .col.t-offset-9{margin-left:75%}body.t .col.t-10{width:83.33333%}body.t .col.t-offset-10{margin-left:83.33333%}body.t .col.t-11{width:91.66667%}body.t .col.t-offset-11{margin-left:91.66667%}body.t .col.t-12{width:100%}body.d .col.d-1{width:8.33333%}body.d .col.d-offset-1{margin-left:8.33333%}body.d .col.d-2{width:16.66667%}body.d .col.d-offset-2{margin-left:16.66667%}body.d .col.d-3{width:25%}body.d .col.d-offset-3{margin-left:25%}body.d .col.d-4{width:33.33333%}body.d .col.d-offset-4{margin-left:33.33333%}body.d .col.d-5{width:41.66667%}body.d .col.d-offset-5{margin-left:41.66667%}body.d .col.d-6{width:50%}body.d .col.d-offset-6{margin-left:50%}body.d .col.d-7{width:58.33333%}body.d .col.d-offset-7{margin-left:58.33333%}body.d .col.d-8{width:66.66667%}body.d .col.d-offset-8{margin-left:66.66667%}body.d .col.d-9{width:75%}body.d .col.d-offset-9{margin-left:75%}body.d .col.d-10{width:83.33333%}body.d .col.d-offset-10{margin-left:83.33333%}body.d .col.d-11{width:91.66667%}body.d .col.d-offset-11{margin-left:91.66667%}body.d .col.d-12{width:100%}body.hd .col.hd-1{width:8.33333%}body.hd .col.hd-offset-1{margin-left:8.33333%}body.hd .col.hd-2{width:16.66667%}body.hd .col.hd-offset-2{margin-left:16.66667%}body.hd .col.hd-3{width:25%}body.hd .col.hd-offset-3{margin-left:25%}body.hd .col.hd-4{width:33.33333%}body.hd .col.hd-offset-4{margin-left:33.33333%}body.hd .col.hd-5{width:41.66667%}body.hd .col.hd-offset-5{margin-left:41.66667%}body.hd .col.hd-6{width:50%}body.hd .col.hd-offset-6{margin-left:50%}body.hd .col.hd-7{width:58.33333%}body.hd .col.hd-offset-7{margin-left:58.33333%}body.hd .col.hd-8{width:66.66667%}body.hd .col.hd-offset-8{margin-left:66.66667%}body.hd .col.hd-9{width:75%}body.hd .col.hd-offset-9{margin-left:75%}body.hd .col.hd-10{width:83.33333%}body.hd .col.hd-offset-10{margin-left:83.33333%}body.hd .col.hd-11{width:91.66667%}body.hd .col.hd-offset-11{margin-left:91.66667%}body.hd .col.hd-12{width:100%}";
d.head.appendChild(s);
}
function size(){
var m = mC() || w.innerWidth < 768 || typeof w.orientation !== 'undefined';
var t = w.innerWidth < 1024 || typeof w.orientation !== 'undefined';
var hd = w.innerWidth > 1920 && typeof w.orientation == 'undefined';
switch(true){
case (m):
change('m','t d hd');
return;
break;
case (!m && t && !hd):
change('t','m d hd');
return;
break;
case (!t && hd):
change('hd','t d m');
return
break;
default:
change('d','m t hd');
}
}
style();
size();
b.style.opacity = 1;
var t = null;
w.addEventListener('resize', function(event){
clearTimeout(t);
t = setTimeout(size,20);
});
function change( add, remove ){
add = add.split(' ');
remove = remove.split(' ');
for(var i=0;i<add.length;i++){
b.classList.add(add[i]);
}
for(var i=0;i<remove.length;i++){
b.classList.remove(remove[i]);
}
}
}(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment