xxxxxxxxxx
body {
display: flex;
min-height: 100vh;
flex-direction: column;
justify-content: center;
align-items: center;
}
/* to make "align-items: center" work: use "min-height: 100vh;"
100vh = 100% Viewport Height */
xxxxxxxxxx
.parent {
position: relative;
}
.child {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
xxxxxxxxxx
.parent{
display: flex;
justify-content: center;
align-items: center;
}
/* Child elements will be perfectly centered automatically */
xxxxxxxxxx
.center {
display: flex;
align-items: center;
justify-content: center;
}
xxxxxxxxxx
.center {
display: flex;
align-items: center;
justify-content: center;
}
xxxxxxxxxx
.container {
min-height: 100vh; // height of the browser viewport
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
xxxxxxxxxx
.name-of-div-to-be-centered {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
xxxxxxxxxx
.container{
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: /* Define the width here; */
height: /* Define the height here; */
}
/*You have to define the width and height! */
xxxxxxxxxx
.<your-outer-div> {
display: flex;
justify-content: center;
align-items: center;
}
xxxxxxxxxx
.parent-div .child-div {
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}