이 10가지 방법 모두 중앙정렬이 가능하다.
/* 기본값 */
.parentContainer{
width: 200px;
height: 200px;
background-color: #333;
}
.childContainer{
width: 100px;
height: 100px;
background-color: salmon;
}
.parentContainer{
position: relative;
}
.childContainer{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.parentContainer{
position: relative;
}
.childContainer{
position: absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
.parentContainer{
display: flex;
justify-content: center;
align-items: center;
}
.parentContainer{
display: flex;
justify-content: center;
}
.childContainer{
align-self: center;
}
.parentContainer{
display: flex;
}
.childContainer{
margin:auto;
}
.parentContainer{
display:grid;
justify-content:center;
align-items:center;
}
.parentContainer{
display:grid;
place-items:center;
}
.parentContainer{
display:grid;
}
.childContainer{
justify-self:center;
align-self:center;
}
.parentContainer{
display:grid;
}
.childContainer{
place-self:center;
}
.parentContainer{
display:grid;
}
.childContainer{
margin:auto;
}