It is not breaking, you are using col-md-
wrong, if you do this (your code):
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
Of course, it will exceed the width and break, except that col-md
uses float
, ie it will try to settle below the element of lesser height.
It's as I explained here:
Your amount of grids is wrong, even if you use .row
, .col-*-3
should have only 4 divs in a .row
, ie for each .row
you should only have 4 .col-md-3
for example.
To know if the quantity always sums the values of the end of col-
, if it ends in -3
then it is 3
, then it must have 4
divs, since the total must always be 12, that is: / p>
- If you only use
.col-*-3
then it will be 4, because 3 + 3 + 3 + 3 = 12
- If you only use
.col-*-4
then it will be 3, because 4 + 4 + 4 = 12
- If you use
.col-*-6
it will be 6 + 6 = 12
- You can also do 6 + 3 + 3 = 12 for example.
To solve with loop, foreach
, for
or while
, you can do this using $i % 4
:
<div class="container">
<h3>cases</h3>
<?php $i = 0; ?>
<?php foreach($cases as $valor){ ?>
<?php
$needarow = !($i % 4);
$i++;//Deve vir depois
?>
<?php if ($needarow) { ?>
<?php if ($i > 1) { ?>
</div> <!-- //fecha .row -->
<?php } ?>
<div class="row">
<?php }?>
<div class="col-md-3">
<img src="<?php echo base_url("inicial/wide_image/".$valor->imagem.'/250/200'); ?>" style="padding:5px;" class='img-responsive'>
<div class="row text-justify">
<h4><?php echo $valor->titulo; ?></h4>
<p><?php echo $valor->descricao; ?></p>
</div>
</div>
<?php } ?>
</div> <!-- //ultimo .row -->
</div> <!-- //fecha .container -->