2016-06-18 84 views
3

如何將風格的徽章舉例爲facebook通知?該值不需要一位數字。它可以是一兩個。在我的嘗試中,我也沒有看到如何以價值爲中心。風格徽章的最佳技巧

#counter { 
 
    display: block; 
 
    width: 18px; 
 
    height: 18px; 
 
    padding: 2px; 
 
    position: absolute; 
 
    font-size: 12px; 
 
    left: 0; 
 
    top: 10px; 
 
    background: red; 
 
    border-radius: 3px; 
 
    text-align: center; 
 
    color: #fff; 
 
}
<span id="counter">12</span>

嘗試將值更改爲1個位數,它不會再看看中心。它稍微偏離。

+1

加上'線height'將其帶到中心 – Sharon

回答

2

#counter { 
 
    display: block; 
 
    padding: 2px 4px; 
 
    position: absolute; 
 
    font-size: 12px; 
 
    left: 0; 
 
    top: 10px; 
 
    background: red; 
 
    border-radius: 3px; 
 
    text-align: center; 
 
    color: #fff; 
 
    line-height:18px; 
 
}
<span id="counter">111</span>

0

#counter { 
 
    display: block; 
 
    width: 18px; 
 
    height: 18px; 
 
    padding: 2px; 
 
    position: absolute; 
 
    font-size: 12px; 
 
    left: 0; 
 
    top: 10px; 
 
    background: red; 
 
    border-radius: 3px; 
 
    text-align: center; 
 
    color: #fff; 
 
    line-height:18px; 
 
}
<span id="counter">1</span>