I have a page where only form exists and I want form to be placed in the center of the screen.
<div class="container">
<div class="row justify-content-center align-items-center">
<form>
<div class="form-group">
<label for="formGroupExampleInput">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
</div>
</form>
</div>
</div>
The justify-content-center
aligns the form horizontally, but I can't figure out how to align it vertically. I have tried to use align-items-center
and align-self-center
, but it doesn't work.
What am I missing?
This is working in IE 11 with Bootstrap 4.3. While the other answers were not working in IE11 in my case.
This work for me:
Bootstrap has text-center to center a text. For example
You change the following
to the following
Update 2019 - Bootstrap 4.3.1
There's no need for extra CSS. What's already included in Bootstrap will work. Make sure the container(s) of the form are full height. Bootstrap 4 now has a
h-100
class for 100% height...Vertical center:
https://www.codeply.com/go/raCutAGHre
the height of the container with the item(s) to center should be 100% (or whatever the desired height is relative to the centered item)
Note: When using
height:100%
(percentage height) on any element, the element takes in the height of it's container. In modern browsers vh unitsheight:100vh;
can be used instead of%
to get the desired height.Therefore, you can set html, body {height: 100%}, or use the new
min-vh-100
class on container instead ofh-100
.Horizontal center:
text-center
to centerdisplay:inline
elements & column contentmx-auto
for centering inside flex elementsoffset-*
ormx-auto
can be used to center columns (.col-
)justify-content-center
to center columns (col-*
) insiderow
Vertical Align Center in Bootstrap 4
Bootstrap 4 full-screen centered form
Bootstrap 4 center input group
Bootstrap 4 horizontal + vertical center full screen
None has worked for me. But his one did.
Since the Bootstrap 4 .row class is now display:flex you can simply use the new align-self-center flexbox utility on any column to vertically center it:
I learned about it from https://medium.com/wdstack/bootstrap-4-vertical-center-1211448a2eff
flexbox can help you. info here