显示图标上的通知数量

Sha*_*ane 14 html css css-position css3 font-awesome

我有一个通知图标(),显示通知的数量.

我在尝试将数字显示在正确的位置时遇到问题,如下图所示

在此输入图像描述

我需要将文本缩小并向右移动一点......这是代码

.header .bubble {
  border-radius: 100%;
  height: 14px;
  width: 14px;
  background-color: rgba(226, 32, 91, 0.77);
  color: #ffffff;
  text-align: top;
  position: relative;
  top: 0px;
  float: right;
  right: -3px;
}

 <a href="javascript:;" id="notification-center" class="icon-set globe-fill" data-toggle="dropdown"><span class="bubble">2</span>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮忙,我是新手.

eir*_*ios 26

example1:使用背景图片

执行此操作的最佳方法是使用position:absolute父级锚点的子跨度.

a.notif {
  position: relative;
  display: block;
  height: 50px;
  width: 50px;
  background: url('http://i.imgur.com/evpC48G.png');
  background-size: contain;
  text-decoration: none;
}
.num {
  position: absolute;
  right: 11px;
  top: 6px;
  color: #fff;
}
Run Code Online (Sandbox Code Playgroud)
<a href="" class="notif"><span class="num">2</span></a>
Run Code Online (Sandbox Code Playgroud)

example2:使用font awesome图标

如果你想使用图标

这是代码

a.fa-globe {
  position: relative;
  font-size: 2em;
  color: grey;
  cursor: pointer;
}
span.fa-comment {
  position: absolute;
  font-size: 0.6em;
  top: -4px;
  color: red;
  right: -4px;
}
span.num {
  position: absolute;
  font-size: 0.3em;
  top: 1px;
  color: #fff;
  right: 2px;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<a class="fa fa-globe">
  <span class="fa fa-comment"></span>
  <span class="num">2</span>
</a>
Run Code Online (Sandbox Code Playgroud)