简体   繁体   English

使用Twitter Bootstrap在Rails中使用Masonry的问题。

[英]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看起来像这样:

带Twitter引导程序和砌体的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.

相关问题 Twitter Bootstrap。 折叠子元素 - Twitter Bootstrap. Collapsing child element Twitter Bootstrap。记住警报关闭行动 - Twitter Bootstrap. Remember alert close action Ruby on Rails和石工问题 - Ruby on Rails and Masonry problems 推特引导。 引导 javascript 正在工作,但其他脚本不会 - Twitter bootstrap. bootstrap javascript is working but others script wont Twitter引导程序。 添加“ affix”类时添加一个新类 - Twitter bootstrap. Add a new class when class“affix” is added Twitter引导程序。 删除之间的空白 <div span> 列中的元素 - Twitter Bootstrap. Remove whitespace between <div span> elements in columns 我该怎么做 <divs> 在Twitter引导程序中使用Jquery Masonry和Twitter Bootstrap以Masonry格式出现? - How do I make <divs> in Twitter bootstrap appear in a Masonry Format with Jquery Masonry and Twitter Bootstrap? 如何使用Rails应用程序正确编辑Twitter Bootstrap 2.0-图像重叠并使其与jQuery Masonry一起使用 - How do I properly edit Twitter Bootstrap 2.0 with my rails app -Images overlapping & making jQuery Masonry work with it 推特引导程序。 为什么模态事件在 JQuery 中有效,而在纯 JS 中无效? - Twitter Bootstrap. Why do modal events work in JQuery but NOT in pure JS? 引导砌体 - Bootstrap Masonry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM