Using media query conditional statements in Tailwind CSS
P粉835428659
P粉835428659 2023-08-10 15:17:27
0
2
535
<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>
P粉835428659
P粉835428659

reply all(2)
P粉676588738

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:

module.exports = {
      variants: {
        backgroundColor: ['responsive', 'hover', 'focus'],
        // ... other configurations
      },
}
P粉492959599

${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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template