【问题标题】:Show number of notifications on icon在图标上显示通知数量
【发布时间】:2017-11-03 13:59:16
【问题描述】:

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

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

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

.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>

谁能帮忙,我是新手。

【问题讨论】:

  • 为什么标题和气泡有相同的css属性?您应该将这个制作标题相对和您的数字在相对内分开
  • 它们的属性不同。 .header .bubble.. 不是 .header,.bubble..
  • 你能做一个小提琴吗?或者至少给我们你的标记

标签: font-awesome html css css-position font-awesome


【解决方案1】:

例子1:使用背景图片

最好的方法是使用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;
}
&lt;a href="" class="notif"&gt;&lt;span class="num"&gt;2&lt;/span&gt;&lt;/a&gt;

例子2:使用字体真棒图标

如果你想使用图标

这是它的代码

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;
}
<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>

【讨论】:

  • 这太完美了!谢谢,请问怎么把图片改成图标? (&lt;i class="fa fa-globe"&gt;&lt;/i&gt;)
  • 您可以应用相对于该图标的位置并执行相同操作
  • 如何让红色文本框变宽?
  • 等待为你的图标制作解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多