I have a component that can display more than 2 cards, and I want my component to display 3 cards max, and allow a scroll x if there are more than 3 cards.
In my code, the 4th card always go on second row.
How to fix this ?
code :
<div class="m-10 w-96 border-2">
<div class="grid w-full grid-cols-3 gap-3 overflow-x-auto">
<button class="flex w-full flex-col gap-1 rounded-xl bg-blue-300 p-3 shadow-md">Button</button>
<button class="flex w-full flex-col gap-1 rounded-xl bg-blue-300 p-3 shadow-md">Button</button>
<button class="flex w-full flex-col gap-1 rounded-xl bg-blue-300 p-3 shadow-md">Button</button>
<button class="flex w-full flex-col gap-1 rounded-xl bg-blue-300 p-3 shadow-md">Button</button>
</div>
</div>
Here is a playground
Thank you for your time.
2
Answers
You probably gonna need a Flex-Box for that
You can try something like this:
I have given each column a fixed width of
7rem
usingtheme('spacing.28')
so that only three of them are visible in yourw-96
container. If that is not necessary then you can use something likeauto
ormax-content
.