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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h1>Pinterest inspired cards layout – JS Version</h1>
<h2>This pen demonstrates how to implement Pinterest Cards Layout <br /> w/ some JavaScript and absolutely positioned elements.</h2>
<h3>I've made a CSS solution (not as elegant as this one) in <a href="https://codepen.io/websanya/pen/eobjk">another pen</a>.</h3>

	<div class="wrapper">

<div class="item">
  <h3>heading 1</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime, alias, dolore, molestias error laboriosam repellat ea minima autem perferendis dolorem nulla doloremque saepe placeat totam fugit impedit repudiandae perspiciatis. Maxime.</p>
  <p>Dicta, quod, reiciendis eaque tenetur odio ipsa nisi delectus veritatis quibusdam praesentium mollitia accusamus maiores alias et quidem voluptatum quaerat unde aut molestiae veniam error. Placeat itaque neque qui voluptatibus!</p>
</div>
		<div class="item">
  <h3>heading 2</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maiores, minus, consectetur, dolore labore magni optio nam cupiditate vel assumenda exercitationem repellat rerum recusandae fugit accusantium nesciunt dolor magnam nihil non.</p>
		</div>
		<div class="item">
  <h3>heading 3</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate, dolores, accusamus corrupti repellendus nemo quasi repellat iste impedit omnis fugiat laborum natus explicabo veritatis quam suscipit nulla nam consequatur cumque?</p>
  <p>Nesciunt, necessitatibus, voluptatem, doloremque laudantium aliquam minus ex sint natus veritatis repellat cum non! Modi, dolorum minus adipisci quia perferendis optio voluptate unde aspernatur placeat sunt! Corporis maxime nihil odit?</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maiores, minus, consectetur, dolore labore magni optio nam cupiditate vel assumenda exercitationem repellat rerum recusandae fugit accusantium nesciunt dolor magnam nihil non.</p>
		</div>
		<div class="item">
  <h3>heading 4</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo, at atque consequatur harum voluptas? Nulla, sint, mollitia, magnam, quis asperiores ad quam autem dolore vitae rem veniam minus earum neque!</p>
  <p>Corporis, inventore eligendi temporibus blanditiis quaerat enim itaque iusto accusantium recusandae voluptas exercitationem doloribus nostrum dolor eaque ullam voluptates sed impedit dolore facilis nesciunt deserunt laudantium ratione saepe quas quae.</p>
		</div>
		<div class="item">
  <h3>heading 5</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A, architecto, soluta perspiciatis velit corporis molestias autem non laboriosam aspernatur optio ad minima! Tempore, recusandae nostrum! In, eveniet sint illum voluptate!</p>
  <p>Autem dicta adipisci nobis quia deleniti accusamus eos hic deserunt voluptate illo! At, natus, dolorum, veniam, atque veritatis vel quasi pariatur necessitatibus similique nostrum voluptatem itaque ipsum autem inventore magni!</p>
		</div>
		<div class="item">
  <h3>heading 6</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, nostrum impedit excepturi dicta laudantium mollitia eos unde doloremque necessitatibus adipisci. Voluptatem, suscipit aliquid distinctio earum itaque culpa a illum eligendi!</p>
  <p>Numquam, cupiditate, debitis ea architecto dignissimos libero aliquam quia totam beatae ex voluptas repellat? Amet, maxime, hic minima quasi nemo eum voluptatum tempore earum voluptas veritatis fugit a ad doloribus.</p>
		</div>
		<div class="item">
  <h3>heading 7</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam, exercitationem, illum nam nemo inventore natus quas dolorum unde impedit maiores vel accusantium omnis laborum dolores quia nobis recusandae delectus esse.</p>
  <p>Cum, esse, harum provident maxime modi fugiat culpa odit eius amet corrupti doloribus minima quo. Commodi, aspernatur, nemo, magnam beatae voluptatibus ullam cum quos rem saepe repellendus consectetur delectus consequuntur.</p>
		</div>
		<div class="item">
  <h3>heading 8</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, inventore, molestiae, molestias totam ut aperiam quod distinctio mollitia omnis consequuntur doloribus nesciunt odio sit adipisci veniam voluptas perferendis animi enim.</p>
  <p>Accusantium, cumque, officia, magnam optio ducimus consectetur asperiores rem explicabo accusamus aliquam porro delectus doloribus quidem odit iste ipsam unde corporis architecto deserunt ex fugit temporibus iure aspernatur itaque ratione.</p>
		</div>
    
	</div>
            
          
!
            
              @import "compass/css3";

/* ====================================
   Some colors
   ==================================== */

$colors: (
  "purple": #9b59b6,
  "orange": #c87f0a
);

/* ====================================
   Demo-specific styles
   ==================================== */

.wrapper {
  position: relative;
  max-width: 960px;
  margin: auto;
  margin-bottom: 2rem;
  background: white;
  @media (max-width: 768px) {
    padding: 1rem;
  }
}

.item {
  position: absolute;
  padding: 1rem;
  width: 31.4%;
  background: map-get($colors, "orange");
  @media (max-width: 768px) {
    width: 100%;
    position: initial;
    margin-bottom: 1rem;
    &:last-of-type {
      margin-bottom: 0;
    }
  }
  h3 {    
    margin: 0 0 1rem;
    border-bottom: 1px solid white;
    text-align: left;
    font-size: 24px;
  }
}

/* ====================================
   Basic styles
   ==================================== */

* {
  @include box-sizing;
}

body {
  background: map-get($colors, "purple");
  color: white;
  font-family: "Helvetica Neue", Helvetica, sans-serif;
  font-weight: 300;
  line-height: 1.5;
}

h1, h2, h3 {
  margin: 0;
  text-align: center;
  font-weight: 300;
}

h1 {
  font-size: 3rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 0.875rem;
  margin-top: 0.875rem;
  margin-bottom: 2rem;
}
            
          
!
            
              var colCount = 0;
var colWidth = 0;
var windowWidth = 0;
var blocks = [];

function positionBlocks() {
  $('.item').each(function () {
    var min = Array.min(blocks),
        index = $.inArray(min, blocks),
        leftPos = margin + (index * (colWidth + margin));
    $(this).css({
      'left': leftPos + 'px',
      'top': min + 'px'
    });
    blocks[index] = min + $(this).outerHeight() + margin;
  });
}

function setupBlocks() {
  windowWidth = $('.wrapper').width();
  if (windowWidth <= 768) { return; }
  colWidth = $('.item').outerWidth();
  margin = (windowWidth - colWidth * 3) /4;
  blocks = [];
  colCount = Math.floor(windowWidth / (colWidth + margin));
  for (var i = 0; i < colCount; i++) {
    blocks.push(margin);
  }
  positionBlocks();
  $('.wrapper').height(Array.max(blocks));
}

$(function () {
  $(window).resize(setupBlocks);
});

// Function to get the Min value in Array
Array.min = function (array) {
  return Math.min.apply(Math, array);
};
// Function to get the Max value in Array
Array.max = function (array) {
  return Math.max.apply(Math, array);
};

$(document).ready(function() {
  setupBlocks();
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console