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

211
Visualizações
CSS backdrop-filter works only if you DON'T set background-color to transparent

I've got a greyscale backdrop-filter applied to a .cover behind one of my overlaid menus. It always has a background color, but when it is .on I sometimes, with JavaScript, want to set the .cover's background-color to an opaque black to darken the background, too.

I have the following CSS being applied to the cover:

body {
    --darkMode: transparent;
}
.cover {
    background-color: #123456;
}
.cover.on {
    -webkit-backdrop-filter: grayscale(100%);
    backdrop-filter: grayscale(100%);
    background-color: var(--darkMode); /* Notable Line */
}

The JavaScript that sets the --darkMode variable is just document.body.style.setProperty("--darkMode", "rgba(0, 0, 0, 0.5)");

However, when darkMode is not enabled, and therefore the .cover's background-color is transparent just like default, the backdrop-filters don't work at all.

You can play around with this with this fiddle.

Thanks for any insights you might have, and have a splendid day, person who was willing to read this question.

EDIT 1: My apologies, the above code was not complete; I have updated to reflect my code more directly, and have added a JS fiddle so you can see it yourself.

EDIT 2: Turns out a solution is to just set the background-color to something like rgba(0, 0, 0, 0.01) instead of transparent.

about 4 years ago · Juan Pablo Isaza
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