Side by side in Bootstrap, jumping line

3

I have a simple problem with Bootstrap v4.0.0-alpha.5.

I search the Database with information. It aligns side by side but in some cases a line is skipped, and only one item remains for the bottom line.

<div class="row">
                <div class="col-md-12">
                    <h2 style="text-align:left; color:white; margin:-top:1%;">Ação/Aventura</h2>

                    <?php

                    require 'conexao.php';

                    $consulta = $PDO->query("SELECT * FROM filmes WHERE categoria1 = 'acaoaventura' ORDER BY id ASC;");

                    while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) { ?>

                    <div class="col-md-2" style="margin:0;margin-bottom:3%;margin-top:2%;padding:0.1%;">

                        <div class="col-md-12" style="margin:0;padding:0;">
                            <a href="filme.php?id=<?php echo "$linha[id]";?>">
                                <img src="<?php echo "$linha[fotodacapa]"; ?>" class="img-fluid">                               
                                <p style="color:yellow; text-align:center; margin:0; padding:0;"><?php echo "$linha[nome]"; ?></p>
                                <div class="col-md-6">
                                    <p style="color:white; text-align:center; margin:0; padding:0;">16 visitas</p></a>
                                </div>

                                <div class="col-md-6">
                                    <a class="venobox_custom" data-type="youtube" href="https://youtu.be/<?php echo "$linha[trailer]"; ?>?autoplay=1"><p style="color:white; text-align:center; margin:0; padding:0;"><i class="fa fa-film" aria-hidden="true"></i> Trailer</p></a>
                                </div>
                            </div>
                        </div>

                        <?php } ?>

                    </div>
                </div>

In this code snippet, I search to show what comes from the database, but I get the following result:

Ihavetriedtochangesomeitemsofplace,buttonoavail.Inanotherwork,Imanagedtogetthe"container", something not recommended, but it worked for me. This time, it did not work.

Any ideas from friends?

Thanks in advance!

Note: Do not look into the Div settings, as I am still testing, I did not organize the classes.

    
asked by anonymous 26.01.2017 / 11:42

4 answers

4
  

/! \ This is a gambiarra!

You can use matchHeight so that all elements are the same size.

Get in link , you can use:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.matchHeight/0.7.0/jquery.matchHeight-min.js"></script>

Then use:

$('.col-md-2').matchHeight();

This will make all elements .col-md-2 have the same height, correcting the problem.

This is the easiest way to resolve this if you are using a single row with elements that exceed the width of the respective row .

    
26.01.2017 / 12:04
7

That's not how the bootstrap grids work, the @inkeliz solution worked the most for coincidence , but it is not the correct solution, especially if it is the way you applied it.

As I explained in Avoid line wrap (collapsing) on col-md bootstrap , then the steps you should take to use GRIDs are basically:

  • Do not use col- within col-
  • The parent element of col- must always be row
  • The sum of all cols must always be 12 , for example:

    • If you have 4 divs with class .col-*-3 then the sum will be 12 (3 + 3 + 3 + 3 = 12)
    • If you have 3 divs with class .col-*-4 then the sum will be 12 (4 + 4 + 4 = 12)
    • You can also do .col-*-6 + .col-*-3 + .col-*-3 for example (6 + 3 + 3 = 12)
  • First you explain where the errors are

    Follow the problems in your HTML:

  • You <div class="col-md-2" style="margin:0;margin-bottom:3%;margin-top:2%;padding:0.1%;"> within col-md-12 , as I said, col- should always go inside row , so it's wrong.

  • You have <div class="col-md-12" style="margin:0;padding:0;"> within col-md-2

  • You have two <div class="col-md-6"> within col-md-12

  • The <a> tag is badly closed: <a href="filme.php?id=<?php echo "$linha[id]";?>"> , you have placed </a> inside another tag, probably not to conflict with the youtube link. But this is wrong.

  • It has two col mixed with other HTML elements that are not part of the grid.

  • Never change the borders of a col- using margin: or margin-left or margin-right , I think top and bottom have no problem. li> Although it does not affect the grids you have an error in your CSS is wrong h2 style="text-align:left; color:white; margin:-top:1%; , has margin:-top , correct is margin-top:1%;

    How to solve

    As I explained here link being PHP you can use something like $i % (numero de colunas desejada), no seu caso você usou "col-md-2" so I think you want 6 columns per lines

    It should look like this:

    <div class="row">
        <div class="col-md-12"> <!-- aqui está certo total é igual 12 -->
            <h2 style="text-align:left; color:white; margin:-top:1%;">Ação/Aventura</h2>
    
            <?php
            require 'conexao.php';
    
            $consulta = $PDO->query("SELECT * FROM filmes WHERE categoria1 = 'acaoaventura' ORDER BY id ASC;");
    
            while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {
            $i = 0;
    
            while ($i < 20) {
    
            $needarow = !($i % 6);
            $i++;//Deve vir depois
            ?>
    
            <?php if ($needarow) { ?>
            <?php if ($i > 1) { ?>
    
            </div> <!-- //fecha .row -->
    
            <?php } ?>
    
            <div class="row">
    
            <?php }?>
    
                <div class="col-md-2" style="margin-bottom:3%;margin-top:2%;padding:0.1%;">
    
                    <!--//acho que nem precisa de col aqui -->
                    <a href="filme.php?id=<?php echo $linha['id'];?>">
    
                        <img src="" class="img-fluid">
                        <p style="color:yellow; text-align:center; margin:0; padding:0;"><?php echo $linha['nome']; ?></p>
                    </a> <!-- Link fechado -->
    
                    <div class="row"> <!--// Row necessário para adicionar -->
                        <div class="col-md-6">
                            <p>16 visitas</p>
                        </div>
    
                        <div class="col-md-6">
                            <a class="venobox_custom" data-type="youtube" href="https://youtu.be/<?php echo $linha[trailer]; ?>?autoplay=1"><p><i class="fa fa-film" aria-hidden="true"></i> Trailer</p></a>
                        </div>
                    </div>
    
                </div>
    
            <?php
            }   //Termina o loop
            ?>
    
            </div> <!-- //fecha o ultimo .row -->
        </div>
    </div>
    
        
  • 26.01.2017 / 20:30
    0

    Put EQUAL height for all elements marked with col-md-2.

    PS: Using styling in HTML is highly unwise, which is why Bootstrap is there, so you do not have to do that.

        
    26.01.2017 / 11:52
    0

    At first, the problem is when your query results in a title with 2 lines and another with 1 only, this causes misalignment and ends up causing you to skip a line.

    You have a few options to resolve:

    Create a larger width so that the texts do not stay on 2 lines, or create a default border at the height of the photo and title squares.

    to keep them aligned.

        
    26.01.2017 / 11:55