Using media query conditional statements in Tailwind CSS
P粉835428659
2023-08-10 15:17:27
<p>How to express this</p>
<pre class="brush:php;toolbar:false;">${window.scrollY > 0 ? " bg-slate-50" : ""}</pre>
<p>Is conditional statement checking only for Tailwind on medium or large screen sizes? </p>
You can easily do this by adding the following code to your code:
className={md:${window.scrollY > 0 ? "bg-slate-50" : "bg-transparent"}}
This is what Tailwind does. Otherwise you can write custom CSS yourself.
Please note, please make sure to include the required variants in your
tailwind.config.js
if not already enabled:${window.scrollY > 0 ? "max-md:bg-slate-50" : ""}
You can also learn more from the Tailwind documentation: https://tailwindcss.com/docs/responsive-design#targeting-a-single-breakpoint