I am a bit confused about the way this code works. I am new to tailwind and I don’t know if I am missing something important, but a simple code that pretends to display a couple of elements horizontally inside a div, and pretends to generate overflow in both X and Y axis, only appears to be working on the Y axis and I don’t understand why. I tried it in vanilla HTML/CSS and it worked as expected, but not in TailwindCSS.
Anyone can try it in the Tailwind Playground (https://play.tailwindcss.com/), just paste the code and you’ll see that the overflow only appears in the Y axis, but not in both as I would want to. Any help is appreciated.
<div class="flex h-[400px] w-[1000px] gap-24 overflow-auto">
<div class="h-[600px] w-[500px] rounded-2xl bg-sky-300/40"></div>
<div class="h-[600px] w-[500px] rounded-2xl bg-sky-300/40"></div>
<div class="h-[600px] w-[500px] rounded-2xl bg-sky-300/40"></div>
<div class="h-[600px] w-[500px] rounded-2xl bg-sky-300/40"></div>
<div class="h-[600px] w-[500px] rounded-2xl bg-sky-300/40"></div>
<div class="h-[600px] w-[500px] rounded-2xl bg-sky-300/40"></div>
</div>
3
Answers
you can play with length and width to find out overflow-x and overflow-y
if you confused about the overflow, you can read this:
overflow-y
overflow-x
This code could fix your code as per your reuirement
scrolling (overflow-y-auto).
1. Used overflow-y-auto on the outer div to allow vertical scrolling.
2. Used flex and overflow-x-auto on the inner div to allow horizontal scrolling for child elements that exceed the container’s width.