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

123
Visualizações
Css inverting everything below an element

Is it possible using css to have an element that inverts everything behind it such that anything that passes below the element will be inverted?

In the example I would like to the circle to be white while passing through the black square, but black otherwise.

.container {
  height: 500px;
  width: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
}

.invert {
  height: 300px;
  width: 300px;
  background-color: black;
}

.move {
  height: 50px;
  width: 50px;
  background-color: black;
  border-radius: 1000px;
  position: absolute;
  top: 0;
  left: 0;
  animation: move linear 5s infinite;
}

@keyframes move {
  0% {
transform: translate(0,0);
  }
  100% {
transform: translate(500px, 500px);
  }
}
<div class="container">
  <div class="invert">

  </div>
  <div class="move">

  </div>
</div>

This needs to be structure agnostic, as in my actual implementation I am using a large number of randomly moving circles as a fixed background, I will not know when they will enter or exit a square, and the relation between circle and square will be different between pages

I've tried filter: invert(1), but it doesn't do what I need it to, I am also curious whether it could be done using svg filters.

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use mix-blend-mode: difference with a white background on your .invert class:

.container {
  height: 500px;
  width: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
}

.invert {
  height: 300px;
  width: 300px;
  background-color: #FFF;
  mix-blend-mode: difference;
  z-index: 1000;
}

.move {
  height: 50px;
  width: 50px;
  background-color: black;
  border-radius: 1000px;
  position: absolute;
  top: 0;
  left: 0;
  animation: move linear 5s infinite;
}

@keyframes move {
  0% {
transform: translate(0,0);
  }
  100% {
transform: translate(500px, 500px);
  }
}
<div class="container">
  <div class="invert">

  </div>
  <div class="move">

  </div>
</div>

The one caveat here is it can only invert elements that appear behind it. so if your .move object needs to be in the DOM after the inverter, you have to change the z-index of one or the other to get them to render correctly.

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