As shown in the Image, truncate happens for all the Category tag component. I want to ensure that only the last few tags will get truncate and if it get truncated to really small tags for instance C… then I don’t have to show that tag in the card.
<span
className=
'cursor-pointer rounded-3xl px-3 py-1 text-xs font-medium text-light-primary/80 dark:text-dark-primary/80 overflow-hidden whitespace-nowrap truncate'
>
{category}
</span>
Can somebody tell me how I can implment this idea ?
I am actually not able to come with an idea on how to implement it.
2
Answers
One thing that may work is limiting the number of tags that the post card is able to display (to maybe 3-5), and optionally hiding the rest of the tags using a (…) tag. This should allow the first few tags that do show up to have more room for text and therefore have less characters truncated.
Not sure if this answers your question entirely but I hope it helps!
To start dynamically truncating from right to left you can do the following
I also added in a check to remove any of the tags that are showing just … after elipssis you can adjust that as you like
here’s the css
here’s a image where i ran it with random array
if i change the size of the filter > 2 then it will look like this
Sorry i couldnt use tailwindcss, but it should be easily convertible