📜  中心绝对元素 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:19.444000             🧑  作者: Mango

代码示例6
.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%) */
}