He’s not breaking it you’re wearing 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>
It is logical that it will exceed the width and break, out that col-md
uses float
, ie it will try to fit under the element of lower height.
It’s like I explained here:
Your grid count is wrong, even if you use the .row
, the .col-*-3
should have only 4 Divs in one .row
, that is to each .row
you must only have 4 .col-md-3
for example.
To know if the quantity always adds up the values of the end of the col-
, ends in -3
so it is 3
, then you must have 4
Therefore the total should always be 12, ie:
- If you’re just gonna use
.col-*-3
then 4, for 3+3+3+3 = 12
- If you’re just gonna use
.col-*-4
then it will be 3, because 4+4+4 = 12
- Use
.col-*-6
will be 6+6=12
- You can also do 6+3+3=12 for example.
To solve with loop, foreach
, for
or while
, can do so 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 -->
They are
display:inline-block
?– Diego Souza
If it’s put a
vertical-align: top
in them and already was.– Diego Souza
if you want to leave them all the same size and/or aligned perfectly, I suggest taking a look at the css-Tricks on the
display:flex
(https://css-tricks.com/snippets/css/a-guide-to-flexbox/). In response to the edge, take the class of elements, and add oneborder: [none~9999+ px] [solid,dashed,inset,outset, etc..] [color (hex,rgb,rgba,etc...)]
– Murilo Melo
@Inkeliz, he may not be using bootstrap, so it is not possible to consider a duplicate hypothesis. :/
– Murilo Melo
@Murilogambôa Pelo
col-md-3
androw
I think it’s Bootstrap and the same alignment problem. I think that your solution also gave an answer to that and the other question as well.– Inkeliz
Put the same height on all.
– Antonio Alexandre
@Antonioalexandre, if he set a height, may occur a div need more height, set this as something fixed is bad :/
– Murilo Melo
Apparently, PHP is generating more than 4 Divs with
col-md-3
(by the image seem to be 6), this is leaving misaligned, since the limit is 12 (4 columns of size 3), two of the columns are thrown down.– Pliavi
If layout problem would be better you post the generated HTML code using the browser developer tool..
– Andre Figueiredo
Exactly, @pliavi, the bootstrap columns have float defined in CSS and since the Divs defined in PHP have different heights, the latter two will be misaligned. I believe that the ideal would be to define a div with the Row class
div classe="row"
every 4 printed elements (or control the height of the elements leaving it fixed, which is a little complicated when it comes to dynamic content).– Woss
@Murilogambôa, you’re right. Height is not the best solution. It would be better to include in line Ivs, but then you need to limit the amount of blocks per line so Ivs don’t climb on top of each other as is happening.
– Antonio Alexandre
@Guilhermenascimento this is bootstrap
– Sr. André Baill
http://www.mkweb.inf.br/site/cases
– Sr. André Baill
Yes are 4 columns.
– Sr. André Baill
@Andrébaill corrected the answer http://answall.com/a/180194/3635
– Guilherme Nascimento
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero