Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda