Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Badge width and height

Tags:

css

badge

I am creating some css badge. The problem is when number is 100 and bigger the last char get out of the badge?

Is it possible to create badge that will be bigger if number is bigger than 99?

Here is my code

CSS

.badge[data-badge]:after {
   content:attr(data-badge);
   font-size:.7em;
   background:rgba(48, 174, 227, 1);
   color:white;
   width:18px;
   height:18px;
   text-align:center;
   line-height:18px;
   border-radius:50%;
   box-shadow:0 0 1px #333;
   margin-top: 7px;
   float:left;
}

HTML

<span class='badge' data-badge='27'></span>

Here is working fiddle https://jsfiddle.net/kx5kow5m/

like image 369
Miomir Dancevic Avatar asked Dec 04 '25 10:12

Miomir Dancevic


2 Answers

Try to set the width: auto and add a min-width: 18px.

Also a padding would be good to add:

width: auto;
min-width: 18px;
paddding: 4px;

Live Fiddle

like image 161
TheYaXxE Avatar answered Dec 07 '25 21:12

TheYaXxE


Set width: auto and add a padding if you need it.

width:auto;
padding: 2px;

Example: https://jsfiddle.net/kx5kow5m/2/

like image 20
TheFrozenOne Avatar answered Dec 07 '25 21:12

TheFrozenOne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!