How can i put this
${window.scrollY > 0 ? " bg-slate-50" : ""}
Conditional statement only for medium or large screens on tailwind?
How can i put this
${window.scrollY > 0 ? " bg-slate-50" : ""}
Conditional statement only for medium or large screens on tailwind?
3
Answers
${window.scrollY > 0 ? "max-md:bg-slate-50" : ""}
you can also get the reference from the documentation of Tailwind for more info:
https://tailwindcss.com/docs/responsive-design#targeting-a-single-breakpoint
You can easily do it by adding this in your code:
className={md:${window.scrollY > 0 ? "bg-slate-50" : "bg-transparent"}}
Thats tailwind way of doing it. otherwise you can always write the custom css.
Note Please make sure to include the required variant in your
tailwind.config.js
if it’s not already enabled:Code:
You can follow this documentation for more info:
https://tailwindcss.com/docs/responsive-design