cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="page">
  <div class="content1">
    <p class="block">grid</p>
    
    <div class="grid">
      <div class="sub1">
        <p class="block">grid</p>
      </div><!--
      --><div class="sub2">
        <p class="block">grid</p>
      </div>
    </div>
  </div><!--
  --><div class="content2">
    <p class="block">grid</p>
    
    <div class="grid">
      <div class="sub1">
        <p class="block">grid</p>
      </div><!--
      --><div class="sub2">
        <p class="block">grid</p>
      </div>
    </div>
  </div><!--
  --><div class="content3">
    <p class="block">grid</p>
    
    <div class="grid">
      <div class="sub1">
        <p class="block">grid</p>
      </div><!--
      --><div class="sub2">
        <p class="block">grid</p>
      </div>
    </div>
  </div>
</div>
            
          
!
            
              /* The gutter is fixed, even within nesting. That saves a lot of trouble. */
$gutter: 15px;

/* This is the mixin for the container. I want to find a way to avoid having to use containers in nested elements, if possible. */
@mixin grid(){
  list-style:none;
  margin:0;
  padding:0;
  margin-left:-$gutter;
}

/* Here is all the shared stuff of the columns. We pass the $x just for passing it to the other mixin inside. */
.column {
  display:inline-block;
  padding-left:$gutter;
  vertical-align:top;
  -webkit-box-sizing:border-box;
  -moz-box-sizing:border-box;
  box-sizing:border-box;
}

/* Here is the mixing that does the trick and calculate the size of the columns. It's separated so it won't rewrite everything in the media-queries. */
@mixin col-width($x) {
  width: $x * 100%;
}

body { margin: 0 auto; padding: $gutter }

/* You need a container for the grid to work, and I don't really like it. If you happen to know a way around it, let me know.  */
.page, .grid { @include grid(); }

/* Mobile first, 'cause that's how I roll */
.content1 { @extend .column; @include col-width(1);
	.sub1 { @extend .column; @include col-width(1/2); }
	.sub2 { @extend .column; @include col-width(1/2); }
}
.content2 { @extend .column; @include col-width(1);
	.sub1 { @extend .column; @include col-width(1/3); }
	.sub2 { @extend .column; @include col-width(2/3); }
}
.content3 { @extend .column; @include col-width(1);
	.sub1 { @extend .column; @include col-width(2/3); }
	.sub2 { @extend .column; @include col-width(1/3); }
}

/* Just for showing the nesting */
$color: #BADA55;
.block { margin: 0; margin-bottom: 12px; padding: 12px; color: #fff }
.content1 .block {  background-color: $color }
.content2 .block {  background-color: darken($color, 20%) }
.content3 .block {  background-color: darken($color, 40%) }


/************************************************************************************
	Add the media-queries normaly, just like you would with normal, pure CSS.

	Here, instead of using the column() mixing, you can use the col-width().
	This way, it won't rewrite everything in the class, only the width,
  avoinding redundance.

************************************************************************************/

@media only screen and (min-width: 481px) and (max-width: 1023px){
    .content1 { @include col-width(1);
		.sub1 { @include col-width(1/2); }
		.sub2 { @include col-width(1/2); }
	}
	.content2 { @include col-width(2/4);
		.sub1 { @include col-width(1/2); }
		.sub2 { @include col-width(1/2); }
	}
	.content3 { @include col-width(2/4);
		.sub1 { @include col-width(2/4); }
		.sub2 { @include col-width(2/4); }
	}
}

@media only screen and (min-width: 1024px){

  body { max-width: 1300px }

  .content1 { @include col-width(2/4);
    .sub1 { @include col-width(1/2); }
    .sub2 { @include col-width(1/2); }
  }
  .content2 { @include col-width(1/4);
    .sub1 { @include col-width(2/3); }
    .sub2 { @include col-width(1/3); }
  }
  .content3 { @include col-width(1/4);
    .sub1 { @include col-width(1/4); }
    .sub2 { @include col-width(3/4); }
  }
}
            
          
!
            
              /******************************************************************************
  Based on the "csswizardry-grids" by Harry Roberts.
  https://github.com/csswizardry/csswizardry-grids/blob/master/csswizardry-grids.scss

  I recomend looking at his code for more information on parts of the css.
  It's REALLY well commented.

******************************************************************************/
            
          
!
999px
Loading ..................

Console