There are plenty of examples of drawing circles around numbers using border-radius. However, the problem I have is that I am displaying numbers in columns and rows (in a table) to form a calendar and when I add a class to put a circle around a selected date using this method it moves the number. I find myself having to fiddle around with padding and such to get both the circle in the right place and the number centered in the circle properly… and then it only works for the precise sizing I set it up for. If someone were to say "can you make that font a bit bigger/smaller" then I would have go through this trial and error process again.
So how can I put a circle around a number without moving the position of the number where it was before I added the circle (and, obviously, have the circle centered on the number)?
3
Answers
A trick you could use is a CSS radial gradient of a transparent "halo":
You can achieve this by using a combination of CSS
::before
or::after
pseudo-elements along withposition: absolute;
.Without knowing the specifics of your HTML, I would suggest using ::after pseudo-class. By doing so, we are drawing a circle "after" the number, but with absolute placement we are centering it in the
td
. And since the number is also centered in thetd
, we have a perfect circle around our number.