Make Bootstrap 4 use 100% screen height

Asked

Viewed 2,173 times

1

Whenever I create a Row no, the size is taken according to the amount of element, then I want to center the card and I can’t, because it doesn’t take 100% of the screen

<div class="container h-100">
<div class="row justify-content-center">
    <div class="col-4 my-auto">
        <div class="card">
            <div class="card-header">
                <div class="row">
                    <div class="col-2">
                        <img src="http://s1134.photobucket.com/user/PW_PrimeiroChefe/media/Kratos.png.html" style="height: 30px; width: 30px;" alt="Logo da Empresa">
                    </div>
                    <div class="col-10">
                        <h5 class="card-title">Login</h5>
                        <h6 class="card-subtitle">nome da empresa</h6>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <form>
                    <div class="form-group">
                        <label for="exampleInputEmail1">Usuário</label>
                        <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">Senha</label>
                        <input type="password" class="form-control" id="exampleInputPassword1">
                    </div>
                    <button type="submit" class="btn btn-primary">Entrar</button>
                </form>
            </div>
        </div>
    </div>
</div>

  • See card centering at: https://jsfiddle.net/maujor/93wdqtz6/15/ Edition here: To center the card set the Row to a height of 100vh.

1 answer

2

Adjust the html, body in the CSS to have the height of the viewport:

html, body{
   height: 100%;
}

Then place the class h-100 also in the .row:

<div class="row justify-content-center h-100">

Example:

html, body{
   height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div class="container h-100">
<div class="row justify-content-center h-100">
    <div class="col-4 my-auto">
        <div class="card">
            <div class="card-header">
                <div class="row">
                    <div class="col-2">
                        <img src="http://s1134.photobucket.com/user/PW_PrimeiroChefe/media/Kratos.png.html" style="height: 30px; width: 30px;" alt="Logo da Empresa">
                    </div>
                    <div class="col-10">
                        <h5 class="card-title">Login</h5>
                        <h6 class="card-subtitle">nome da empresa</h6>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <form>
                    <div class="form-group">
                        <label for="exampleInputEmail1">Usuário</label>
                        <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">Senha</label>
                        <input type="password" class="form-control" id="exampleInputPassword1">
                    </div>
                    <button type="submit" class="btn btn-primary">Entrar</button>
                </form>
            </div>
        </div>
    </div>
</div>

  • Thank you, man, I would have tried that, but here’s the thing, I’m wearing Angular 5.x. x, I was assigning body size in the css of the Component and not the app-root. But anyway, your answer made me open my eyes. Vlw ;)

Browser other questions tagged

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