Vertically and horizontally centering text in circle in CSS (like iphone notification badge)

后端 未结 5 649
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 06:50

I\'m looking for a way of to do a cross-browser iphone-like badge in CSS3. I\'d obviously like to use one div for this, but alternative solutions would be fine. The importan

5条回答
  •  遥遥无期
    2020-12-04 07:20

    Modern Solution

    The result is that the circle never gets distorted and the text stays exactly in the middle of the circle - vertically and horizontally.

    .circle {
      background: gold;
      width: 40px; 
      height: 40px;
      border-radius: 50%;
      display: flex; /* or inline-flex */
      align-items: center; 
      justify-content: center;
    }
    text

    Simple and easy to use. Enjoy!

提交回复
热议问题