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 Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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.

            
              h1 Flexbox is broken.
p Or sort of. Please read the pen description ;) 

p.header Here's an alternative approach using grid and an autofill minmax() / autofit based number of columns. 
p.instruction Resize the frame width to check the how elements grows, shrinks and wraps

h2 Growing / Shrinking  width elements
p Using auto-fill minmax();

- var elements = 11;

- var n = 1;
.grid
  while n <= elements
    div
      h1= n++

h2 Fixed width elements, space-around style
p Using auto-fill minmax() and justify-items: center

- var n = 1;
.grid.fix-grid--around
  while n <= elements
    div.fix-el
      h1= n++

h2 Fixed width elements, space-between style
p Using auto-fit and justify-content:space-between

- var n = 1;
.grid.fix-grid--between
  while n <= elements
    div.fix-el
      h1= n++

h2 Flexbox issue demo
p With growing / shrinking elements and space-between

- var n = 1;
.flex
  while n <= elements
    div
      h1= n++
      
h2 Flexbox issue demo
p With fixed width elements and space-between

- var n = 1;
.flex.space-bt
  while n <= elements
    div
      h1= n++
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Roboto');

/*SASS variable that determine the "min-width" of the elements*/
$bp: 140px;

.grid{
  /*sets the container as a grid with variable number of columns*/
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax($bp,1fr));
  grid-gap:1em;
  margin:1em 0 3em;
}

.grid div{
  height: $bp;
  /*just centering the numbers*/
  display:flex;
  align-items:center; 
  justify-content:center;
}

/*random color generator, from @joshuajcollinsworth 's awesome pen, so credit where it's due :) https://codepen.io/joshuajcollinsworth/pen/aEJGvg*/
@for $i from 1 through 11 {
	$red: random(255);
	$green: random(255);
	$blue: random(255);
	.grid div:nth-child(#{$i}), .flex div:nth-child(#{$i}){
		background: rgb($red, $green, $blue);
  }
}

/* modifiers for the grid with fixed width elements, space-around style example*/
.fix-grid--around{
  justify-items: center;
  grid-column-gap:0;
}
/* modifiers for the grid with fixed width elements, space-between style example*/
.fix-grid--between{
  grid-template-columns: repeat(auto-fit, $bp);
  justify-content: space-between;
  grid-column-gap:0;
}

.fix-el{
  width: $bp;
}

/*for the flexbox demonstration*/
.flex{
  margin-top: 1em;
  display:flex;
  flex-flow: row wrap;
  justify-content:space-between;
}

.flex div{
  flex: 1 1 $bp;
  height: $bp;
  display:flex; 
  justify-content:center;
  align-items:center;
  margin:1em;
}

/* for flexbox fixed width demonstration*/
.space-bt div{
  flex: 0 0 $bp;
}

/* aesthetic thingies*/
body{
  font-family: 'Roboto', sans-serif;
  color:#333;
  background: #FFF0E0;
}

body>h1{/*clickbait :p */
  color:#F00;
  font-size:4rem;
}

body>h1, body>h2, {
  margin:1rem 1rem 0 1rem; 
}
body>p{
  margin:0.5rem 1rem;
}

.header{
  font-size:1.5em;
}

.instruction{
  font-size:1.3em;
  color:steelblue;
}
            
          
!
            
              /* SASS random color generator, from @joshuajcollinsworth 's awesome pen, so credit where it's due :) https://codepen.io/joshuajcollinsworth/pen/aEJGvg*/
            
          
!
999px
Loading ..................

Console