Show number of notifications on icon
Asked Answered
E

1

18

I have a notification icon () which shows the number of notifications.

I am having a problem trying to get the number to display in the correct position, as shown in see below image

enter image description here

I need the text to be smaller and move right and up a little... here is the code

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

Can anyone help, I am new to this.

Ellary answered 3/8, 2015 at 10:0 Comment(4)
Why do the header and bubble have same css properties? You should separete this making header relative and your number absolute within the relativeLenette
They don't have the same properties. .header .bubble.. not .header, .bubble..Enliven
Can you please make a fiddle ? Or at least give us your markupTheophrastus
jsfiddle.net/q84ydjr0Ellary
H
33

example1: using background image

The best way to do this is to use position:absolute to child span of parent anchor.

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;
}
<a href="" class="notif"><span class="num">2</span></a>

example2: using font awesome icon

If you want to use icon

this is code for it

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>
Hachmann answered 3/8, 2015 at 10:17 Comment(4)
This is perfect! Thank you, how would I change the image to an icon? (<i class="fa fa-globe"></i>)Ellary
you can apply position relative to that icon and do this sameHachmann
And how do I make the red text box wider?Ellary
wait making solution of for your iconHachmann

© 2022 - 2024 — McMap. All rights reserved.