Responsive bootstrap layout

Asked

Viewed 3,520 times

2

I’m creating a system using bootstrap, to make it responsive I used the classes col-xs-12 col-md-2, when I resize the page the responsiveness works perfectly, but when I use the mobile mode of the Chrome the site gets the original size.

inserir a descrição da imagem aqui

How it should look inserir a descrição da imagem aqui

HTML

@extends('layouts.app', ["current" => "clientes"])
<style>
    .img-card-user{
        width:220px;
        border-radius:50%;
    }
    .img-mini-card{
        width:50px;
    }
    .centered {
        margin: 0 auto !important;
        float: none !important;
    }
</style>
@section('body')
    <h2>Ultimo cliente cadastrado</h2>
    <p class="text-secondary">Esse foi o ultimo cliente cadastrado.</p>
    <div class="bs-callout bs-callout-primary">
        <div class="card-body">
            <div class="row">
                <div class="col-xs-12 col-md-3 centered">
                    <img alt="Responsive image" class="img-card-user mx-auto d-block"  src="/img/clientes/jademS.jpg">
                </div>
                <div class="col-xs-12 col-md-6 centered" style="padding-top:15px;">
                    <h4 class="text-primary">{{ $lastCliente->Nome }}</h4>
                    <small class="text-dark">Desenvolvedor back-end</small>
                    <div class="text-secondary" style="margin-top:15px;">
                        <ul style="list-style-type: none; padding-left:0px;">
                            <li><b>Idade: </b>{{ $lastCliente->Idade }}</li>
                            <li><b>Departamento:</b>@php $departamento = $departamentos->find($lastCliente->departamento_id) @endphp {{ $departamento->nome }}</li>
                            <li><b>Descriação:</b> {{ $lastCliente->descricao }}</li>
                        </ul>
                    </div>
                    <div class="row" style="font-size:24px; padding-left:15px;">
                        <i style="margin-right:10px;" class="fab fa-facebook-square"></i>
                        <i style="margin-right:10px;" class="fab fa-github"></i>
                        <i style="margin-right:10px;" class="fab fa-instagram"></i>
                    </div>
                </div>
                <div class="col-xs-12 col-md-2" style="padding-top:15px; font-size:20px;">
                    <span class="badge badge-primary full">Skills</span>
                    <span class="badge badge-secondary full">PHP 7 <i class="fab fa-php"></i></span>
                    <span class="badge badge-secondary full">Laravel 5.6 <i class="fab fa-laravel"></i></span>
                    <span class="badge badge-secondary full">Bitcoin <i class="fab fa-bitcoin"></i></span>
                </div>
            </div>
        </div>
    </div>
    <p class="text-right text-secondary"> Data de cadastro: {{ date('d/m/y', strtotime($lastCliente->created_at)) }} </p>
    <h2>Clientes</h2>
    <div class="card border">
        <div class="card-body">
            <ul class="list-group">
                @foreach($clientes as $cliente)
                <li class="list-group-item">
                    <img class="img-card-user img-mini-card" src="/img/clientes/mandela.jpg">
                    {{ $cliente->Nome }} <small class="text-secondary">@php $departamento = $departamentos->find($cliente->departamento_id) @endphp {{ $departamento->nome }}</small>
                    <a class="btn btn-primary float-right" href="/cliente/destroy/{{ $cliente->id }}" style="margin-top:10px;">Excluir</a>
                </li>
                @endforeach
            </ul>
        </div>
    </div>
@endSection
  • All the places where you have col-Xs-12, you should only put col-12, apparently you are using BS4, but the classes of the BS3 grid, test and tell me what gave there, because with this code you can not test here, or put for us the direct HTML copied from the Browser, gives a Ctrlu in the window and copies the HTML from there already rendered!

  • I changed but it stayed the same

  • I put all html here https://notepad.pw/boostratpnotwork

  • Here was perfect... must be something else you put there....... http://prntscr.com/mxy9a4 In fact it seems that the layout only breaks to a certain extent... I’ll see http://prntscr.com/mxya4k

  • strange it may be some conf of my machine ?

  • Young I answered you, I think it will solve your problem there, qq doubt comments there that I help you

Show 1 more comment

2 answers

3


Your code has two problems, the main one is that you are not using the meta tag viewport, without it your page is not responsive in the right way. Add inside your <head> the tag below

<meta name="viewport" content="width=device-width, initial-scale=1">

I recommend you read here about the tag viewport: How to declare and use the @viewport rule?

The other problem is that you set up a grid with 11 columns inside the body-card, with that the text is stuck, was 3-6-2 = 11. I switched to 4-6-2 = 12 and the text is no longer hidden.

inserir a descrição da imagem aqui

Follow the image code above:

.container{
        margin-top:80px;
        margin-bottom:80px;
    }    
    .img-card-user{
    width:220px;
    border-radius:50%;
}
.img-mini-card{
    width:50px;
}
.centered {
    margin: 0 auto !important;
    float: none !important;
}
<link rel="stylesheet" type="text/css" media="screen" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Sistema de gerenciamento</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText"
    aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarText">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" href="/">Home</a>
      </li>
      <li class="nav-item active dropdown">
        <a class="nav-link dropdown-toggle" id="linkClientes" role="button" data-toggle="dropdown" href="#">Clientes</a>
        <div class="dropdown-menu" aria-labelledby="linkClientes">
          <a class="dropdown-item" href="/clientes">Lista de clientes</a>
          <a class="dropdown-item" href="/cliente/novo">Cadastro</a>
        </div>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" id="linkClientes" role="button" data-toggle="dropdown" href="#">Departamentos</a>
        <div class="dropdown-menu" aria-labelledby="linkClientes">
          <a class="dropdown-item" href="/departamentos">Lista de departamentos</a>
          <a class="dropdown-item" href="/departamento/novo">Cadastro</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/about">about</a>
      </li>
    </ul>
    <span class="navbar-text">
      IBico solutions
    </span>
  </div>
</nav>
<div class="container">
  <main role="main">
    <h2>Ultimo cliente cadastrado</h2>
    <p class="text-secondary">Esse foi o ultimo cliente cadastrado.</p>
    <div class="bs-callout bs-callout-primary">
      <div class="card-body">
        <div class="row">
          <div class="col-12 col-md-4 centered">
            <img alt="Responsive image" class="img-card-user mx-auto d-block" src="https://placecage.com/100/100">
          </div>
          <div class="col-12 col-md-6 centered" style="padding-top:15px;">
            <h4 class="text-primary">Marcos</h4>
            <small class="text-dark">Desenvolvedor back-end</small>
            <div class="text-secondary" style="margin-top:15px;">
              <ul style="list-style-type: none; padding-left:0px;">
                <li><b>Idade: </b>33</li>
                <li><b>Departamento:</b> Finanças</li>
                <li><b>Descriação:</b> Give me money</li>
              </ul>
            </div>
            <div class="row" style="font-size:24px; padding-left:15px;">
              <i style="margin-right:10px;" class="fab fa-facebook-square"></i>
              <i style="margin-right:10px;" class="fab fa-github"></i>
              <i style="margin-right:10px;" class="fab fa-instagram"></i>
            </div>
          </div>
          <div class="col-12 col-md-2" style="padding-top:15px; font-size:20px;">
            <span class="badge badge-primary full">Skills</span>
            <span class="badge badge-secondary full">PHP 7 <i class="fab fa-php"></i></span>
            <span class="badge badge-secondary full">Laravel 5.6 <i class="fab fa-laravel"></i></span>
            <span class="badge badge-secondary full">Bitcoin <i class="fab fa-bitcoin"></i></span>
          </div>
        </div>
      </div>
    </div>
    <p class="text-right text-secondary"> Data de cadastro: 14/03/19 </p>
    <h2>Clientes</h2>
    <div class="card border">
      <div class="card-body">
        <ul class="list-group">
          <li class="list-group-item">
            <img class="img-card-user img-mini-card" src="/img/clientes/mandela.jpg">
            Marcos <small class="text-secondary"> Finanças</small>
            <a class="btn btn-primary float-right" href="/cliente/destroy/9" style="margin-top:10px;">Excluir</a>
          </li>
          <li class="list-group-item">
            <img class="img-card-user img-mini-card" src="/img/clientes/mandela.jpg">
            Bruno <small class="text-secondary"> Segurança da informação</small>
            <a class="btn btn-primary float-right" href="/cliente/destroy/8" style="margin-top:10px;">Excluir</a>
          </li>
          <li class="list-group-item">
            <img class="img-card-user img-mini-card" src="/img/clientes/mandela.jpg">
            Evandro <small class="text-secondary"> Desenvolvimento</small>
            <a class="btn btn-primary float-right" href="/cliente/destroy/7" style="margin-top:10px;">Excluir</a>
          </li>
        </ul>
      </div>
    </div>

  </main>
</div>

  • made the changes you recommended and worked perfectly thank you

  • @Cool evandroignacio that worked there, success with the project. []s

-2

Only supplemented that it would not need the css class col-12 on these three lines:

div class="col-12 col-md-4 centered">
div class="col-12 col-md-6 centered" style="padding-top:15px;">
div class="col-12 col-md-2" style="padding-top:15px; font-size:20px;">

Once the css class has been used container and has not been set a width for the items, they will stack up if the portview is less than medium.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.