Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class="hidden sm:flex" doesn't work in TailwindCSS

Tags:

tailwind-css

I want to make my navbar responsive by adding hidden sm:flex to a specific item. Meaning it'll hidden by default but show only on small screens and above. I made some debug and discover that hidden override everything even the responsive variants. Other display properties work will on responsive variants. here's my code:

className="hidden sm:flex sm:w-2/5 w-11/12 mt-4 sm:mt-0 items-center shadow-md"
like image 638
Ahmed Hossam Avatar asked Apr 20 '26 02:04

Ahmed Hossam


1 Answers

Tailwind is driven by mobile first design, just like bootstrap and some other CSS frameworks. Reference: https://tailwindcss.com/docs/responsive-design/#mobile-first

That means that classes without variants will be applied to smaller screens first, and then you can add variants for bigger screens.

So, the thing that you want to achieve should be like this:

className="flex md:hidden w-2/5 md:w-11/12 mt-0 md:mt-4 items-center shadow-md"

I hope this helps!

like image 65
Ben Avatar answered Apr 21 '26 19:04

Ben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!