垂直水平居中
<div class="parent">
  <div class="child"></div>
</div>1
.parent {
    display: flex;
    align-items: center;
    justify-content: center;
}2
.parent {
    display: grid;
}
.child {
    justify-self: center;
    align-self: center;
}3
.parent {
    position: relative;
}
.child {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}Last updated
Was this helpful?