4

I've activated Masonry on the parent element (an unordered list) that houses the modified list items listed below (with Chrome's F12 DEV tools showing the margin-bottom and margin-right in the pink-ish color):

Masonry Problem before Resizing

When the document is loaded, the above occurs despite the CSS of each list item being the following;

li {
    background-color: #fff;
    border: 1px solid #dfdfdf;
    float: left;
    padding: 20px;
    position: relative;
    width: calc(50% - 10px);
    margin-right: 10px;
    margin-bottom: 10px;
}

The jQuery I used is the following;

$(document).ready(function(){
    $("ul").masonry({
        itemSelector: 'li'
    });
});

Once the window is resized horizonally, however, the CSS styles come into effect as shown below;

Masonry Problem Solved by Resizing

Any idea as to how I can acheive the above on page load?

UPDATE*

JSFiddle: Click here. If the said problem doesn't appear, try clicking the 'Run' button (Ctrl + Return).

3 Answers3

6

For the webkit browser problem I simply added $(window).load(function(){ before ('#masonry').masonry({. Now the margin-bottom is fine on every item on every browser.

truemiro
  • 95
  • 1
  • 7
2

It works finde as sone as I add gutter: 10 ;

$("ul#news").masonry({
    itemSelector: 'li',
    gutter: 10
});

Explenation: http://masonry.desandro.com/options.html#gutter

j_s_stack
  • 659
  • 1
  • 5
  • 18
0

I had the same problem until now.

I've removed all margins altogether and let masonry handle it ("gutter"-option) and it works fine!

Hope that helps!

Mario Haubenwallner
  • 1,525
  • 1
  • 14
  • 21