DIV 讓數字水平垂直置中?
代言
代言 2017-02-24 14:52:44
0
2
820
.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>

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


代言
代言

Antworte allen(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;
        
    }


Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!