Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <ul id="masonry360">
  
  <li class="m360_element"><div class="m360_inside small g360_flexall">1</div></li>
  <li class="m360_element"><div class="m360_inside medium g360_flexall">2</div></li>
  <li class="m360_element"><div class="m360_inside big g360_flexall">3</div></li>
  <li class="m360_element"><div class="m360_inside xlarge g360_flexall">4</div></li>
  <li class="m360_element"><div class="m360_inside big g360_flexall">5</div></li>
  <li class="m360_element"><div class="m360_inside xlarge g360_flexall">6</div></li>
  <li class="m360_element"><div class="m360_inside small g360_flexall">7</div></li>
  <li class="m360_element"><div class="m360_inside large g360_flexall">8</div></li>
  <li class="m360_element"><div class="m360_inside small g360_flexall">9</div></li>
  <li class="m360_element"><div class="m360_inside large g360_flexall">10</div></li>
  <li class="m360_element"><div class="m360_inside small g360_flexall">11</div></li>
  <li class="m360_element"><div class="m360_inside big g360_flexall">12</div></li>
  
</ul>
              
            
!

CSS

              
                /* CSS reset */
html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {margin: 0;padding: 0;border: 0;font-size: 100%;font: inherit;vertical-align: baseline;}
article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;}
blockquote, q { quotes: none; }
blockquote:before, blockquote:after,
q:before, q:after { content: ""; content: none; }
ins { background-color: #ff9; color: #000; text-decoration: none; }
mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; }
del { text-decoration: line-through; }
abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; }
table { border-collapse: collapse; border-spacing: 0; }
hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }
input, select { vertical-align: middle;}
@import url(http://fonts.googleapis.com/css?family=Roboto:400,100,700);
body {font-family: 'Roboto', sans-serif;background-color:#204e5f;}
* {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;}
.g360_flexall {display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-ms-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;}


#masonry360 {float:left;width:100%;list-style-type:none;padding:0;margin:0;}
#masonry360 .m360_element  {float:left;height:auto;width:20%;padding:5px;}

.m360_inside {float:left;width:100%;}
.m360_inside.small {height:200px !important;background-color:#ffc6a8;}
.m360_inside.medium {height:250px !important;background-color:#ff8984;}
.m360_inside.big {height:300px !important;background-color:#b7d7d8;}
.m360_inside.large {height:350px !important;background-color:#edf7f5;}
.m360_inside.xlarge {height:400px !important;background-color:#ffe1a8;}

@media screen and (max-width: 1600px) {
	ul#masonry360 .m360_element  {width:20%;}
}


@media screen and (max-width: 1200px) {
	ul#masonry360 .m360_element  {width:25%;}
}

@media screen and (max-width: 812px) {
	ul#masonry360 .m360_element  {width:33.333%;}
}

@media screen and (max-width: 500px) {
	ul#masonry360 .m360_element  {width:50%;}
}

@media screen and (max-width: 350px) {
	ul#masonry360 .m360_element  {width:100%;}
}
              
            
!

JS

              
                (function () {
  
  "use strict";
  
  function moveElement(element,row,el) {

    element.style.position = "absolute";

    // position of 'parent' element
    var rowAbove = row-1; // the row above
    var parentElement = document.getElementById("row"+rowAbove+"el"+el); // this element is oriented

    // dims of parent
    let rect = parentElement.getBoundingClientRect();
    let left = rect.left;
    let top = rect.top;
    let width = rect.width;
    let height = rect.height;
    let bottom = rect.bottom;
    let right = rect.right;

    // calculate new pos of Element
    var newYPos = height+top;
    var newXPos = left;

    // style it
    element.style.width = width+"px";
    element.style.left = newXPos+"px";
    element.style.top = newYPos+"px";

  }

  function positioning(m360_elements,mainW,elW,elementsInRow) {

    var row = 1;
    var el = 0;

    for (var i = 0 ; i < m360_elements.length ; ++i) {   

      if (el === elementsInRow) {
        row++;
        el = 1;
      } else {
        el++;
      }

      m360_elements[i].dataset.row = row;
      m360_elements[i].dataset.el = el;
      m360_elements[i].setAttribute("id","row"+row+"el"+el); // set unique ID
      //m360_elements[i].childNodes[0].innerHTML = "row:"+row+", element:"+el;

      var element = m360_elements[i];

      // positioning
      if (row !== 1) {

        moveElement(element,row,el);

      } else {

        element.style.width = "";
        element.style.left = "";
        element.style.top = "";
        element.style.position = "relative";

      }

    } 

  }

  function init() {

    var holder = document.getElementById("masonry360");
    let rect = holder.getBoundingClientRect();
    let mainW = rect.width;

    var elW = 0;
    var m360_elements = document.getElementsByClassName('m360_element');
    elW = m360_elements[0].offsetWidth; // element width (representative for all)

    var elementsInRow = Math.round(mainW/elW); // how much elements are in one row?

    console.log(elementsInRow+' elements in row');

    positioning(m360_elements,mainW,elW,elementsInRow);

  }

  window.onload = function () {init();}
  window.onresize = function () {init();}
  window.orientationchange = function () {init();}

}());
              
            
!
999px

Console