A
A
Alexander2016-05-06 09:33:42
css
Alexander, 2016-05-06 09:33:42

How to align the height of bootstrap columns in the news loop?

Help me please. Already screwed up. There is such a code

<div class="container">
  <div class="row">

<!-- Этот блок выводится в цикле (например 12 записей) -->

    <div class="col-md-6">
      Это некая новость
    </div>

<!-- -->

Конец цикла

  </div>
</div>

When displaying news of different lengths, the blocks become different heights 5276f0b25f4c462896d06ad810d2758d.png
And I need this 2ab315d8f9e44d3ca40fb3bc0363756d.png
Maybe you can somehow display div.clearfix after every second block

Answer the question

In order to leave comments, you need to log in

6 answer(s)
Сергей Тутуков, 2016-05-06
@vintkor

codepen.io/STutukov/pen/grgZrW

G
GreatRash, 2016-05-06
@GreatRash

Используя именно бутстрап - никак. Колонки в CSS не предполагают одинаковости высот. Дизайнеры об этом не догадывались, не догадываются и никогда не догадаются. Поэтому вам придётся переопределять бутстраповские стили:

.container.container-as-table {
  display: table;

  width: 100%;
  border-collapse: collapse;
}

.container-as-table .row {
  display: table-row;
}

.container-as-table .col {
  display: table-cell;
}

Евгений, 2016-05-06
@Nc_Soft

Можно на row повесить класс flex-row

@media only screen and (min-width : 768px) {
    .flex-row.row {
        display: flex;
        flex-wrap: wrap;
    }
    .flex-row.row > [class*='col-'] {
        display: flex;
        flex-direction: column;
    }
}

Александр, 2016-05-06
@alexmixaylov

в цикле есть счетчик i (ну или что там у вас)
if (i%2 == 0){
//четное
//деление на два без остатка
}
если счетчик нечетный выводить

<div class="row">
    <div class="col-md-6">
      Это некая новость
    </div>
здесь нет закрывающего тега див

если счетчик четный выводить
<div class="col-md-6">
      Это некая новость
    </div>
    </div>
здесь второй закрывающий див, но нет div.row

A
alex_ok83, 2016-05-08
@alex_ok83

я сделал проще

<div class="col-xs12">
<div class="col-md-4">Новость</div>
<div class="col-md-4">Новость</div>
<div class="col-md-4">Новость</div>
</div>
<div class="col-xs12">
<div class="col-md-4">Новость</div>
<div class="col-md-4">Новость</div>
<div class="col-md-4">Новость</div>
</div>

V
Viktor Taran, 2016-05-11
@shambler81

The problem is not new, so all solutions have pros and cons of
the solution we use, since it is not custom and does not require additional js styles, etc.
All you need to do is insert a line every 2nd and 3rd element. which is easily done in php in a completely standard way of the engine.
Plus, the solution is simplicity and reliability, any amount of content and complexity of layout inside the div will not affect the result in any way.

<div class="col-lg-4 col-md-6"><div>
<div class="col-lg-4 col-md-6"><div>
          <div class="col-md-12 visible-md">
<div class="col-lg-4 col-md-6"><div>
        <div class="col-lg-12 visible-lg">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question