Good afternoon, such a problem, made a login form. Align horizontal with the help of margin: 0 auto;
. But not vertically align, how to make the center (vertical)?
4 answers
top: calc(50% - высота_блока/2); left: calc(50% - ширина_блока/2);
|
as an option
.modal{ padding: 50px; background: #ccc; position: fixed; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); }
<div class="modal"></div>
|
Understood, maybe someone will need, added:
position: fixed; top: 50%; left: 50%; margin-top: -...; margin-left: -...;
Instead of points, block size / by 2.
|
Point to parent
display: flex; // FlexBox align-items: center; // выравнивает по вертикали justify-content: center; //выравнивает по горизонтали
|