search

Home  >  Q&A  >  body text

css - UC手机浏览器下如何让div水平垂直居中。

UC浏览器在宽高固定下,margin:auto,上下左右0;不能水平垂直居中是什么原因?

CSS#globalTip{
    position: fixed;
    left: 0;
    right: 0;
    top:0;
    bottom:0;
    z-index: 99999;
    width:75%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    background-color: #000;
    color:#fff;
    font-size: 1.6rem;
    border-radius: 20px;
}

如果position:absolute就可以,但这并不是我想要的。

PHP中文网PHP中文网2813 days ago1069

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 11:12:16

    display: table-cell;
    vertical-align: middle;

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:12:16

    I later changed to another horizontal and vertical writing method

    css#globalTip{
        position: fixed;
        left:50%;
        top:50%;
        z-index: 99999;
        margin-left: -35%;
        margin-top:-25px;
        width:75%;
        height: 50px;
        line-height: 50px;
        text-align: center;
        background-color: nth($theme-color,1);
        color:#fff;
        font-size: 1.6rem;
        border-radius: 20px;
    }
    

    But I still want to know how to solve the bug in UC Browser using the original writing method

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:12:16

    Use in absolute and fixed positioning modes

    #globalTip{
        position: fixed;
        left:50%;
        top:50%;
        -webkit-transform:translate3d(-50%,-50%,0);
        transform:translate3d(-50%,-50%);
    }

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:12:16

    I also encountered the same problem
    Horizontal and vertical centering under uc does not matter
    Solution

    .box{
        display: flex;
        justify-content: center;
        align-items: center;
    }

    reply
    0
  • Cancelreply