Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
TailwindCss's mobile breakpoints do not work

I am building a custom navbar in Gatsby using TailwindCss for styling. For reference I am following a tutorial on YouTube which's code can be found here.

When I use the mobile breakpoints as prefix like in the example below only the div saying "mobile" works as it should be:

Layout.js

<nav>
  <div className={"flex"}>
    <div className={"hidden md:flex"}>desktop</div>
    <div className={"md:hidden"}>mobile</div>
  </div>
</nav>

tailwind.config.js

module.exports = {
  content: ["./public/**/*.html", "./src/**/*.{js,jsx,ts,tsx,vue}"],
  darkMode: "class",
  theme: {},
  plugins: []
};

styles/global.css

@tailwind base;
@tailwind components;
@tailwind screens;
@tailwind utilities;

The output "desktop" should be shown when the text "mobile" vanishes but for some reason it doesn't. Am I doing something wrong or is there a problem with Tailwind?

enter image description here

EDIT: Reproduction example here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The problem seems to be in your global.css file.

You should not add the @tailwind screens;. Since you are using the latest TailwindCSS, @tailwind screens; was deprecated since 2.2 in JIT mode and it's now named: @tailwind variants;

Tailwind Changelog

As of v2.2, the @tailwind screens directive has been renamed to @tailwind variants, since it is now the injection point for all variants, not just responsive variants.

Some more info on when the @tailwind variants; should be added:

The @tailwind variants feature is considered an advanced escape hatch and we recommend omitting it by default. You should only use it if your project won't work properly without it, which is only ever really true if you are introducing Tailwind to a legacy system with a very fragile existing CSS codebase that has styles that absolutely need to be at the very end of the stylesheet for things to work.

Also, according to the Tailwind installation with Gatsby instructions You should not add the @tailwind variants;

That being said, you should not need it in this case so, by just removing it in you global.css file will fix the issue.

Your new global.css file should be:

@tailwind base;
@tailwind components;
@tailwind utilities;

Here is a working CodeSandbox

about 4 years ago · Juan Pablo Isaza Report

0

Problem solved after I have noticed that the autoprefixer plugin was missing in the postcss.config.js. Just redid the installation for Gatsby.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!