xxxxxxxxxx
.container {
display: grid;
place-items: center;
height: 100vh;
}
xxxxxxxxxx
<div class="container">
<div class="child"></div>
</div>
.container {
display: flex;
justify-content: center;
align-items: center;
}
xxxxxxxxxx
center{
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
xxxxxxxxxx
/* Assume the div has a class of "center"
The below would center it horizontally
*/
.center {
margin-left: auto;
margin-right: auto;
}
/* There is a shorthand and it is given below */
.center {
margin: 0 auto;
}
xxxxxxxxxx
div.center {
text-align: center;
align-items: center;
align-self: center;
justify-content: center;
justify-self: center;
justify-items: center;
justify-tracks: center;
text-justify: center;
place-items: center;
place-self: center;
padding-left: center;
vertical-align: middle;
line-height: 100%;
margin: auto;
position: absolute;
left: 50%;
right: 50%;
transform: translate(-50%, -50%);
}
xxxxxxxxxx
.parent {
display : flex;
justify-content : center;
align-items : center;
}
xxxxxxxxxx
div {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}