div水平垂直居中

div.parent{
   display:flex;
   justify-content: center;
   align-items: center;
}
div.parent{
    position:relative;
}
div.child {
    position: absolute; 
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);  
}
div.parent {
    display: grid;
}
div.child {
    justify-self: center;
    align-self: center;
}
div.parent{
    font-size: 0;
    text-align: center;
    &::before {
        content: "";
        display: inline-block;
        width: 0;
        height: 100%;
        vertical-align: middle;
    }
}
div.child{
    display: inline-block;
    vertical-align: middle;
}
div.parent{
    display:flex;
}
div.child{
    margin:auto;
}

你可能感兴趣的:(div水平垂直居中)