html - 如何在 Font Awesome 圆圈内居中放置文本

标签 html css font-awesome

我在下面有 css/html,我想将圆圈内的文本居中。如果只有一位数字,我可以计算出正确的 margin ,但我希望它始终有效,即使有两位或三位数字。有人对此有好的解决方案吗?

.circle-stack {
    position: absolute;
    display: inline-block;
    width: 10px;
    height: 10px;
    top: 25px;
    left: 5px;
}
		
.fa-circle-thin,
.points-indicator {
    position: absolute;
}
.fa-circle{
  font-size: 16px;
  color: #c0cff6;
}

.points-indicator {
  color: #1f0e3e;
  font-weight: bold;
  top: 1px;
  left: 4px;
  width: 5px;
  height: 5px;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="circle-stack">
  <i class="fa fa-circle" aria-hidden="true"></i>
  <a href="/notifications" title="Unread notifications"><span class="points-indicator">10</span></a>
</div>

最佳答案

我认为不需要 Font Awesome 库。你可以简单地这样做:

.circle{
  width:100px;
  height:100px;
  border-radius:50%;
  box-sizing:border-box;
  text-align:center;
  display:inline-block;
  line-height:100px;
  background-color:#000;
}
.circle a{
  text-decoration:none;
  color:#fff;
  font-size: 30px;
}
<div class="circle">
  <a href="#">10</a>
</div>
<div class="circle">
  <a href="#">100</a>
</div>
<div class="circle">
  <a href="#">1000</a>
</div>

关于html - 如何在 Font Awesome 圆圈内居中放置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44124641/

相关文章:

html - Internet Explorer 不会使用@font-face 显示字体图标

android - HTML5 视频不会在 Android 设备上循环播放

html - 将绝对元素定位到右边 :0 of document

html - 可以将多个图像分组到一个 div 中吗

html - 从网站复制和粘贴 - 字体粗细 : bold versus <b>

css - 使用 Ruby Gem 不显示 Font Awesome 图标

javascript - Slick-Slider 下一个和上一个按钮未激活

html - 如何在两列布局的div内放置内边距

javascript - 如果产品缺货,则显示属性 Magento

javascript - 如何将javascript附加到 Font Awesome 图标