Implement dynamic media query settings using Tailwind CSS
P粉141911244
P粉141911244 2023-08-26 20:54:45
0
1
573

In my React JS application I have a component and I want to set a mobile breakpoint based on a variable:

 const Component = ({size}) => { return ( 
hello
) }

I want to add something like [size]:flex where md:flex will set a breakpoint based on that property. (eg: if the size is 500px or 100px or 900px, set it to display flex)

Question: Is it possible to set media queries the way I described above?

P粉141911244
P粉141911244

reply all (1)
P粉710478990

You can useclassnamesnpm package:

const rootClassName = cn( // 首先添加任何tailwind classNames "h-full flex flex-col", // 这是条件部分。根据size属性,定义className { [md:flex-1]: size === "A", [sm:flex-1]: size === "B", } )
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!