[英]Problems with Masonry in Rails, using Twitter Bootstrap.
Here is a JSFiddle of what my site looks like currently: https://jsfiddle.net/4u4xx1yg/ 这是我目前网站的JSFiddle: https ://jsfiddle.net/4u4xx1yg/
There is an empty space between divs, which is why I'm trying to use Masonry to make the divs appear like this: div之间有一个空的空间,这就是为什么我试图使用Masonry让div看起来像这样:
I'm using Bootstrap with Rails 4. I'm creating two columns with each_slice(). 我正在使用带有Rails 4的Bootstrap。我正在使用each_slice()创建两个列。 I tried the following, using the Masonry Rails gem , but it doesn't work yet:
我尝试了以下,使用Masonry Rails gem ,但它还没有用:
<div id="masonry-container">
<% @projects.each_slice(2) do |projects| %>
<div class="col-md-6 box">
<% projects.each do |project| %>
<p><%= project.name %></p>
<% end %>
</div>
<% end %>
</div>
And I added this to application.js: 我把它添加到application.js:
$(function(){
$('#masonry-container').masonry({
itemSelector: '.box',
});
});
What am I doing wrong with Masonry? 我在砌体上做错了什么?
In application.js, I have: 在application.js中,我有:
//= require masonry/masonry.min
And in application.css.scss, I have: 在application.css.scss中,我有:
/*
*= require 'masonry/basic'
*/
I got this to work by editing the CSS of: 我通过编辑CSS来实现这个目的:
#masonry-container {
margin: 0 auto;
}
.box {
width:450px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.