Aula 26 – Loja Online – Django – Tutorial Bootstrap – Linhas e Colunas

Aula 26 – Loja Online – Django – Tutorial Bootstrap – Linhas e Colunas

Loja Online - Django - Linhas e Colunas

Loja Online – Django – Linhas e Colunas

Voltar para página principal do blog

Todas as aulas desse curso

Aula 25                  Aula 27

Se gostarem do conteúdo dêem um joinha 👍 na página do Código Fluente no
Facebook

Esse é o link do código fluente no Pinterest

Meus links de afiliados:

Hostinger

Digital Ocean

One.com

Para baixar o código como está até agora, acesse o link abaixo:
https://github.com/toticavalcanti/django_ecommerce/tree/row_col_bootstrap

Rows e Columns – Linhas e Colunas

A forma como o bootstrap enxerga o espaço no browser é parecido com uma planilha.

Planilha

Planilha

Em uma planilha, você tem colunas de A, B, …,  Z, AA, AB, AC, …, AZ …e C ∞.

E linhas 1, 2, 3, …∞

Apesar de parecido com uma planilha na analogia, o bootstrap funciona um pouco diferente.

Colunas(col)

O bootstrap funciona com um sistema de grade, por isso parece com uma planilha.

Esse sistema dele, permite até 12 colunas em uma página, não importa a largura da tela, ele sempre vai dividir o espaço em 12 pedaços.

É assim que ele formata o conteúdo na tela do browser.

Essas colunas podem ser usadas individualmente ou agrupadas.

Para agrupar as colunas, você precisa criar linhas.

Linha(row)

Para criar linhas, adicione uma div com class=”row”.

A  quantidade de linhas não importa.

Vamos em frente, criaremos uma linha(row) dentro do dentro do container em /templates/bootstrap/example.html,dentro da row criaremos uma coluna(col) e dentro dessa col colocaremos o alert-primary.

/templates/bootstrap/example.html

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        <title>Bootstrap example</title>
    </head>
    <body>
        <div class='container'>
            <div class="row">
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
            </div>
        </div>
        <div class='container-fluid'>
            <div class="alert alert-secondary" role="alert">
                A simple secondary alert—check it out!
            </div>
        </div>

        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
</html>

Com o servidor rodando acesse:

http://127.0.0.1:8000/bootstrap/

Veja que nada mudou, porque só temos uma coluna, por isso, ela ocupou os 12 pedaços da tela, ou seja, a tela inteira.

Vamos adicionar um alert-secondary em uma segunda coluna na mesma linha para ver o que acontece.

/templates/bootstrap/example.html

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        <title>Bootstrap example</title>
    </head>
    <body>
        <div class='container'>
           <div class="row">
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
                <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
            </div>
        </div>
        <div class='container-fluid'>
            <div class="alert alert-secondary" role="alert">
                A simple secondary alert—check it out!
            </div>
        </div>

        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
</html>

Com o servidor rodando acesse novamente:

http://127.0.0.1:8000/bootstrap/

Agora temos na primeira linha, duas colunas, uma com alert-primary e a outra com um alert-secondary.

A segunda linha com o alert-secondary ocupando toda a tela é do class=’container-fluid’.

Agora vamos criar 12 colunas ao todo, iguais a essas que criamos, ou seja, 12 colunas alternadas: alert-primary e alert-secondary.

Vamos adicionar um alert-secondary em uma segunda coluna na mesma linha para ver o que acontece.

/templates/bootstrap/example.html

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        <title>Bootstrap example</title>
    </head>
    <body>
        <div class='container'>
           <div class="row">
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
               </div>
               <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
           </div>
        </div>
        <div class='container-fluid'>
            <div class="alert alert-secondary" role="alert">
                A simple secondary alert—check it out!
            </div>
        </div>

        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
</html>

Acesse novamente:

http://127.0.0.1:8000/bootstrap/

Como não definimos o tamanho das colunas, ele fez uma formatação padrão.

As colunas podem ter tamanho de 1 a 12.

Vamos colocar todas as colunas com tamanho 1 para as 12 colunas ficarem na mesma linha.

/templates/bootstrap/example.html

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        <title>Bootstrap example</title>
    </head>
    <body>
        <div class='container'>
           <div class="row">
               <div class="col-1">
                   <div class="alert alert-primary" role="alert">
                       A simple primary alert—check it out!
                   </div>
               </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
               </div>
               <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
           </div>
        </div>
        <div class='container-fluid'>
            <div class="alert alert-secondary" role="alert">
                A simple secondary alert—check it out!
            </div>
        </div>

        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
</html>

Acesse novamente:

http://127.0.0.1:8000/bootstrap/

Vamos adicionar 12 colunas no container-fluid e ver a diferença do container para o container-fluid.

/templates/bootstrap/example.html

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        <title>Bootstrap example</title>
    </head>
    <body>
        <div class='container'>
           <div class="row">
               <div class="col-1">
                   <div class="alert alert-primary" role="alert">
                       A simple primary alert—check it out!
                   </div>
               </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
               </div>
               <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
           </div>
        </div>
        <div class='container-fluid'>
           <div class="row">
               <div class="col-1">
                   <div class="alert alert-primary" role="alert">
                       A simple primary alert—check it out!
                   </div>
               </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
               </div>
               <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
                <div class="col-1">
                    <div class="alert alert-primary" role="alert">
                        A simple primary alert—check it out!
                    </div>
                </div>
               <div class="col-1">
                    <div class="alert alert-secondary" role="alert">
                         A simple secondary alert—check it out!
                    </div>
                </div>
           </div>
        </div>

        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
</html>

Acesse novamente:

http://127.0.0.1:8000/bootstrap/

É isso, ficamos por aqui.

Aula 25                  Aula 27

Todas as aulas desse curso

Voltar para página principal do blog

Para baixar o código como está até agora, acesse o link abaixo:
https://github.com/toticavalcanti/django_ecommerce/tree/row_col_bootstrap

Se gostarem do conteúdo dêem um joinha 👍 na página do Código Fluente no
Facebook

Link do código fluente no Pinterest

Novamente deixo meus link de afiliados:

Hostinger

Digital Ocean

One.com

Obrigado, até a próxima e bons estudos. 😉

 

About The Author
-

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>