DIV 讓數字水平垂直置中?
代言
代言 2017-02-24 14:52:44
0
2
818
.unsolve
{
    position: absolute;
    right: 10px;
    top:50%;
    transform: translate(0,-50%);
    z-index: 1;
    font-size: 13px;
    background-color: red;
    border-radius: 50%;
    color:#fff;
    width: 15px;
    height: 15px;
    padding: 5px;
    text-align: center;
}

<div class="unsolve">12</div>

這樣設定的時候,數字都會中間偏下,沒辦法完全中間。請問該怎麼讓他完全水平垂直置中?


代言
代言

répondre à tous(2)
phpcn_u933

只要添加:line-height : (div高度)px

就可以文字居中了

大家讲道理
.unsolve
    {
        position: absolute;
        right: 10px;
        top:0;
        bottom: 0;
        margin:auto;
        z-index: 1;
        font-size: 13px;
        background-color: red;
        border-radius: 50%;
        color:#fff;
        width: 15px;
        height: 15px;
        line-height: 15px;
        padding:5px;
        text-align: center;
        
    }


Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!