css center vertically
/* Answer to: "css vertical align middle" */
/*
Go to: https://www.w3schools.com/css/css_align.asp
Here you can learn many ways to align horizontal and vertically!
My favourite method is below:
*/
.center {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
border: 3px solid green;
}
<style>
.container {
height: 200px;
position: relative;
border: 3px solid green;
}
.center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
<div class="container">
<div class="center">
<p>I am vertically and horizontally centered.</p>
</div>
</div>
<style>
.container {
height: 200px;
position:
relative;
border: 3px solid green;
}
.center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform:
translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
<div
class="container">
<div class="center">
<p>I am vertically and horizontally centered.</p>
</div>
</div>