How to add badge on top of Font Awesome symbol?

后端 未结 5 809
温柔的废话
温柔的废话 2020-12-12 10:56

I would like to add badge with some number (5, 10, 100) on top of the Font Awesome symbol (fa-envelope). For example:

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 11:04

    While @Paulie_D's answer is good, it doesn't work so well when you have a variable width container.

    This solution works a lot better for that: http://codepen.io/johnstuif/pen/pvLgYp

    HTML:

    
      
      
    
    

    CSS:

    .fa-stack[data-count]:after{
      position:absolute;
      right:0%;
      top:1%;
      content: attr(data-count);
      font-size:30%;
      padding:.6em;
      border-radius:999px;
      line-height:.75em;
      color: white;
      background:rgba(255,0,0,.85);
      text-align:center;
      min-width:2em;
      font-weight:bold;
    }
    

提交回复
热议问题