在对象上调用每个方法时,如何使用CSS显示Flex列



我正在尝试显示:每个项目(产品(上的flex列,但导致在垂直布局中展示它(代码如下(,我想知道如何在显示为flex,以及在不对称布局列(通过每个对象循环时(时。谢谢你!

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}
/* Create three equal columns that floats next to each other */
.column {
  display: flex;
  margin:20px;
  float: left;
  width: 33.33%;
  padding: 10px;
  height: 300px; /* Should be removed. Only for demonstration */
}
/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}
</style>
</head>
<body>
<h2>All Products</h2>
<% @products.each do |product| %>

<div class="row">
  <div class="column" style="background-color:#aaa;">
    <%= product.product_name %>
    <%= product.description %>
  </div>

</div>
<% end %>
</body>
</html>

我不明白..但是也许您可以尝试这样做

<div class="row">
    <div class="column">
        <%= product.product_name %>
        <%= product.description %>
    </div>
    <div class="column">
        <%= product.product_name %>
        <%= product.description %>
    </div>
    <div class="column">
        <%= product.product_name %>
        <%= product.description %>
    </div>
</div>

使用CSS文件:

.row{
     display: flex;
}
.column{
     width:33%;
}

我建议您使用bootstraphttps://getbootstrap.com/

P.S。如果将宽度设置为33%,则水平填充或边距会弄乱它。

最新更新