【问题标题】:Getting all list-group-items to be the same size使所有列表组项目的大小相同
【发布时间】:2014-08-08 16:00:03
【问题描述】:
<div class="list-group">
  <p class="list-group-item-text">(one line)</p>
  <p class="list-group-item-text">(one line)</p>
  <p class="list-group-item-text">(two lines)</p>
</div>

我希望所有.list-group-item-text 都具有相同的高度,即最大的高度。

所以从上面的代码来看,前两项会扩大到第三项的大小。

我试过this solution,但没有响应。

编辑:Here 是解决方案,由karan3112 提供

【问题讨论】:

标签: css twitter-bootstrap


【解决方案1】:

使用下面的代码循环遍历每个项目,并使用一个临时变量来获取最大值。

将项目的内部内容包装在一个 div 中,在本例中为 .list-group-item-wrapper

编辑:使用 outerHeight()

JS

    var temp = 0;
    $('.list-group .list-group-item-wrapper').each(function (index) {
      if($(this).outerHeight() > temp)
      {
        temp = $(this).outerHeight();
      }          
     });
    $('.list-group .list-group-item-wrapper').css('min-height',temp);

DEMO

【讨论】:

  • 虽然较小的列表项确实扩大了,但它们仍然小于最大的列表项。
  • 给出你的代码的小提琴链接,以便我更好地理解。
  • 这是因为.list-group-item-text 的填充。尝试将a 标签包裹在一个 div 中,并使用上述逻辑中的 div 来计算最大高度。
  • 这是一个很好的解决方案。但是,当窗口极度缩小时,高度又不同了。
猜你喜欢
  • 1970-01-01
  • 2018-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
相关资源
最近更新 更多