xxxxxxxxxx
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
xxxxxxxxxx
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
xxxxxxxxxx
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
xxxxxxxxxx
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
xxxxxxxxxx
#content {
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 100px; /* Need a specific value to work */
}
xxxxxxxxxx
//How to center an absolute div
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
this is a new way to center things which are positioned absolute
xxxxxxxxxx
.absolute{
inset:0;
margin: auto
}
xxxxxxxxxx
position:absolute;
left:0;
right:0;
margin-left:auto;
margin-right:auto;
xxxxxxxxxx
.parent {
height: 100vh;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
xxxxxxxxxx
.child {
position: absolute;
top: 50%; /* position the top edge of the element at the middle of the parent */
left: 50%; /* position the left edge of the element at the middle of the parent */
transform: translate(-50%, -50%); /* This is a shorthand of
translateX(-50%) and translateY(-50%) */
}