简体   繁体   English

媒体查询在 Tailwind CSS 中不起作用

[英]Media Queries not Working in Tailwind CSS

Media Queries in TailWind CSS are not working Well. TailWind CSS 中的媒体查询无法正常工作。

My Code is this我的代码是这个

<img src={MYIMAGE} alt="Test Image" className="h-6 w-8 rounded-md gfold:h-8 gfold:w-14 gfold:rounded-xl sm:h-16 sm:w-24 " />

gfold -> (400px) - A Media Size included by me in the tailwind.config.js file. gfold -> (400px) - 我在tailwind.config.js文件中包含的媒体大小。
sm -> (640px) - A Default Media Size that Comes with Tailwind. sm -> (640px) - Tailwind 附带的默认媒体大小。

When Media Size is below sm size is correct, But when my screen is greater than the sm size the Size is not Changing .当媒体尺寸低于sm尺寸时是正确的,但是当我的屏幕大于sm尺寸时,尺寸不会改变

Now what should I do?现在我该怎么办? Please help me , I am new to Tailwind CSS.请帮助我,我是 Tailwind CSS 的新手。

First of all with tailwind css, the media queries are used for larger screens, the default css is applied for mobile, so keep that in mind首先,使用 tailwind css,媒体查询用于更大的屏幕,默认 css 用于移动设备,因此请记住这一点

i would suggest the standard breakpoints defined by tailwind instead of overwriting the config file ,我建议使用由顺风定义的标准断点,而不是覆盖配置文件,

 <img src={MYIMAGE} alt="Test Image" className="h-6 w-8 rounded-md md:h-full md:w-full" />

this will set the picture to full dimensions when screen is larger than 768px.当屏幕大于 768px 时,这会将图片设置为全尺寸。

also make sure when you define a new breakpoint in tailwindcss to add the following to the config file还要确保在 tailwindcss 中定义新断点时将以下内容添加到配置文件中

 const defaultTheme = require('tailwindcss/defaultTheme') module.exports = {theme: {screens: {'gfold' :'400px' ,...defaultTheme.screens},}}

you can check how tailwind logic is made with media queries in: https://learnjsx.com/category/1/posts/mediaQueries您可以在以下位置检查如何使用媒体查询创建顺风逻辑: https : //learnjsx.com/category/1/posts/mediaQueries

I found the Answer for my Question.我找到了我的问题的答案。
It can be found inside this Github thread它可以在这个 Github线程中找到
HUGE Thank to Adam Wathan for this Answer.非常感谢Adam Wathan的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM