Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery masonry: nth-child() adds unneeded margin to child nodes

I am trying to use the awesome jquery masonry plugin -> http://desandro.com/resources/jquery-masonry/

The plugin works just fine, however I have problems creating a layout where I use an nth-child() selector to get rid of a margin-right on every third element.

#footerwidgets li.widget {
    margin: 0px 24px 24px 0px;
    width:340px;
}

#footerwidgets li.widget:nth-child(3n) {
  margin-right:0px;
}

Since my container for this widget is exactly 1068px wide, three widgets fit in perfectly (because the last widget has no right margin).

When I try to use the jquery masonry plugin, this behaviour gets ignored! Only two columns fit in. (The plugin works, so all widgets get floated in masonry style.) When I inspect the elements, every third element has a right margin of 24px as well. So nth-child is ignored.

Any way to make that working?

like image 306
matt Avatar asked Dec 21 '22 17:12

matt


1 Answers

With jQuery, remove margins and use Masonry's gutterWidth option in its place.

CSS:

#footerwidgets li.widget.masonry-brick { margin: 0; }

jQuery:

$('#footerwidgets').masonry({
  gutterWidth: 24
});
like image 149
desandro Avatar answered Feb 24 '23 17:02

desandro