【问题标题】:Cards with dependent 3 rows (same height of all 3 rows)具有相关 3 行的卡片(所有 3 行的高度相同)
【发布时间】:2022-11-26 03:47:36
【问题描述】:

我想创建一个商店,在那里我将把物品分成 3 行。

1 行 - 标题 2排-图片 3 行 - 添加到购物车按钮/数量可供选择/有条件地显示多个下拉菜单/有关商品的某些信息等等

根据项目的标题,1 行的高度可能不同。 3 行的高度可能因内容而异。

有没有办法使所有行的高度相同并相互依赖?

因此,如果显示许多项目,则所有行都需要始终基于最高行处于相同的高度。

所以:

项目 6 - 最高的 1 行 = 所有 1 行都必须适应这个高度 项目 9 - 最高的 2 行 = 所有 2 行都必须适应这个高度

等等

我正在使用 angular 和 bootstrap - 我认为它可能由卡组解决,但我找不到办法......

谢谢 !

【问题讨论】:

  • 您能否在您尝试实现此目标的地方分享代码 sn-p,stackblitz 会很棒,因为其他人可以使用它并快速帮助您

标签: angular row height equals


【解决方案1】:

使用网格类并覆盖一些 CSS 规则,您可以使所有行的所有卡片具有相同的高度。

试试下面的代码

<div class="cards-container grid">
    <div class="card">...</div>
    ...
</div

.cards-container.grid {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  grid-auto-rows: 1fr;
}

.cards-container.grid .card {
  width: 100%;
  border: 1px solid black
}
<link href="https://getbootstrap.com/docs/5.2/assets/css/docs.css" rel="stylesheet">

<div class="cards-container grid">
  <div class="card">
    <svg class="bd-placeholder-img card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Image cap" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"></rect><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image cap</text></svg>

    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content. Some quick example text to build on the card title and make up the bulk of the card's content.Some quick example text to build on the card title and make</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>

  <div class="card">
    <svg class="bd-placeholder-img card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Image cap" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"></rect><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image cap</text></svg>

    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>

  <div class="card">
    <svg class="bd-placeholder-img card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Image cap" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"></rect><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image cap</text></svg>

    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>

  <div class="card">
    <svg class="bd-placeholder-img card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Image cap" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"></rect><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image cap</text></svg>

    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>
</div>

【讨论】:

    猜你喜欢
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2020-06-11
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    相关资源
    最近更新 更多