A fixed width
needs to be set on .notification-badge
, equal to its height
.
.notification-badge {
width: 13px;
}
To determine the correct value, inspect the element and get its height in px
. Keep in mind that if box-sizing
is set to border-box
, padding
and border
values are included in the total width
and height
. Considering different vertical and horizontal padding
values, it's advisable to set the width
slightly lower by 2px
than the height
. To center the text inside the now fixed width element, you can utilize flexbox:
.notification-badge {
width: 13px; /* adjust based on desired dimensions */
display: flex;
justify-content: center;
}
View it in action here:
@import url('https://fonts.googleapis.com/css?family=Roboto');
.notification-badge {
position: relative;
color: #ffffff;
background-color: #FF4081;
border-radius: 50%;
padding: 5px;
font-family: "Roboto";
font-size: 12px;
}
.notification-icon--fixed {
max-height: 60px;
width: 60px;
}
.notification-badge {
width: 14px;
display: flex;
justify-content: center;
letter-spacing: -1px;
}
<a data-activates="mdi-social-group-add" title="Convites" style="" class="notification-button notification-icon--fixed">
<div class="block-elem">
<i class="mdi-social-group-add large">
<small class="notification-badge">22</small>
</i>
</div>
</a>
<a data-activates="mdi-social-group-add" title="Convites" style="" class="notification-button notification-icon--fixed">
<div class="block-elem">
<i class="mdi-social-group-add large">
<small class="notification-badge">1232</small>
</i>
</div>
</a>
<a data-activates="mdi-social-group-add" title="Convites" style="" class="notification-button notification-icon--fixed">
<div class="block-elem">
<i class="mdi-social-group-add large">
<small class="notification-badge">3855</small>
</i>
</div>
</a>
Javascript can also be used to dynamically set the width of the element:
$(window).on('load', function(){
$('.notification-badge').each(function() {
$(this).css({width: ($(this).height() - 2) + 'px'})
})
})
Note that the 2px
padding difference is taken into account.