HTML:
<div class="container">
<div class="inner">
this is a box fixed in center of screen<br>The second line
</div>
</div>
CSS:
.father{
display: flex;
align-items: center;
justify-content: center;
}
:before和display:inline-block
HTML:
<div class="father">
<div class="son">
this is a box fixed in center of screen<br>The second line
</div>
</div>
CSS:
.father {
text-align: center;
background-color: red;
}
.father:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
.son {
display: inline-block;
}
HTML:
<div class="inner">
this is a box fixed in center of screen
</div>
CSS:
.inner {
position:fixed;
top: 50vh;
left: 50vw;
transform: translate(-50%, -50%);
}