css - 每行四个产品 Bootstrap/ROR 停止使用添加的信息?

标签 css ruby-on-rails ruby twitter-bootstrap ruby-on-rails-4

我在使用 Ruby on Rail 的 in_groups_of 方法以 4 为一组显示产品行时遇到问题。当我的代码如下时,它完美地工作:

<% @products.in_groups_of(4, false).each do |row| %>
<div class="center">
  <td>
    <tr>
        <% for product in row %>
          <product>
            <u><%= link_to "#{product.title}", product_path(product) %></u>
          </product>    
    </tr>    
  </td>        
</div>

但是,当我尝试添加其他产品信息时,所有产品都居中。这是添加了附加信息的页面:

<% @products.in_groups_of(4, false).each do |row| %>
<div class="center">
  <td>
    <tr>
        <% for product in row %>
          <product>
            <u><%= link_to "#{product.title}", product_path(product) %></u>
          </product>

          <%= image_tag product.picture.url if product.picture? %>
          <% if product.active == false %>
            <p>Sorry, this product is not available at this time.</p>
          <% else %>
             <div id="paypalbutton"><%= raw product.paypalbutton %></div>
          <% end %>

        <% end %>  
    </tr>    
  </td>        
</div>
<% end %>

我认为我的 SCSS 可能是问题所在,但我不确定是什么导致它崩溃。页面中使用的所有SCSS如下:

.products {
  list-style: none;
  margin: 0;
  li {
    overflow: auto;
    padding: 10px 0;
    border-bottom: 1px solid $gray-lighter;
  }
}

product {
  font-size: 1.5em;
  letter-spacing: -1px;
  margin-bottom: 30px;
  font-weight: normal;
  color: $dark-gray-darker;
  u {
    text-decoration: underline;
  }
}

#paypalbutton {
  height: 50px;
  width: 200px;
  margin:0 auto;
}

删除 'margin:0 auto;'来自#paypalbutton 也没有改变任何东西。

最佳答案

我不认为这是解决这个问题的正确方法,但我使用卡片和导航栏类让它工作

<div class="container-center">
<% @products.in_groups_of(4, false) do |group| %>
  <% for product in group %>
    <ul class="nav navbar-nav">
      <li>
        <div class="card" style="width: 25rem;">

          <%= image_tag product.picture.url if product.picture? %>

          <div class="card-block">
            <h3 class="card-title">
              <u><%= link_to "#{product.title}", product_path(product) %></u>
            </h3>

            <div class="center">
              <% if product.active == false %>
                <p class="card-text">Sorry, this product is not available at this time.</p>
              <% else %>
                <div class="card-text" id="paypalbutton"><%= raw product.paypalbutton %></div>
              <% end %>
            </div>

          </div>
        </div>
      </li>
    </ul>
  <% end %>
<% end %>
</div>

关于css - 每行四个产品 Bootstrap/ROR 停止使用添加的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48196483/

相关文章:

php - 在 opencart 产品页面中没有得到正确的输出

html - 添加与正文大小相同的元素时显示滚动条

jquery - 文本不下降一行,溢出 :hidden, jScrollpane

javascript - Foreach 元素悬停不同的背景

ruby-on-rails - 我可以按文件将 RuboCop Rails/DynamicFindBy 方法列入白名单吗

ruby-on-rails - 从 Rails 1.2.3 升级到 2.3.5 有多难?

ruby-on-rails - 从命令行调试/执行 Discourse 插件

ruby-on-rails - 将 CSV 文件导入 Rails sqlite3 数据库

ruby - 无法在 Mac OSX 10.7.5 上安装 Ruby 1.9.3

ruby-on-rails - 如何定义返回带字符串键的哈希的 Factory Girl 工厂?