For some numbers in a text, I want give them a appearance of coins.
This seems pretty easy at first: put them in a span background and apply some border-radius
.
But how achieve a quadratic box (to get a circle with border-radius
)?
First I tried display: inline flow-root
to have a block formatting context and be able to set height with aspect-ratio: 1/1
.
But with this the box grows only to bottom. How do I center the box, but let its content stay on the normal text line? vertical-align: middle
would center the box, but moves content too, so coin number wouldn’t stay at the baseline with the surrounding text.
And furthermore in block formatting context coin box with three digit numbers will push the lines apart.
Is there a solution to get a quadratic box for inline elements, which don’t push lines apart? (it is okay the box for this coin numbers overlap the surrounding lines a bit)
.coinDukat {
position: relative;
display: inline-block;
border-radius: 50%;
padding: 0.2em;
min-width: 1.1em;
aspect-ratio: 1/1;
background: goldenrod;
color: #815d05;
text-align: center;
/*vertical-align: middle;*/
}
<p>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ipsum dolor sit sadipscing elitr, ipsum dolor sit amet, consetetur sadipscing elitr. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <span class="coinDukat">1</span> sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
<p>Lorem ipsum dolor sit amet, sit Preis: <span class="coinDukat">300</span>. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt <span class="coinDukat">50</span> magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
2
Answers
I remembered the pattern with a absolute positioned
::before
pseudo element: In addition this works with an image for background (in my case a circular metal texture)But does anybody know, why i need to set z-index on the span?
I would fake this with some
clip-path
and an overflowing background.The border is used to create the overflowing background: https://css-tip.com/overflowing-background/
Related question to understand the
71%
of theclip-path
: clip-path:circle() radius doesn't seem to be calculated correctly